|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { describe, it } = require('../helpers/mocha'); |
| 4 | +const { expect } = require('../helpers/chai'); |
| 5 | +const { |
| 6 | + buildTmp, |
| 7 | + processExit |
| 8 | +} = require('git-fixtures'); |
| 9 | +const stats = require('../../src/stats'); |
| 10 | +const { |
| 11 | + assertNoStaged |
| 12 | +} = require('../helpers/assertions'); |
| 13 | +const { initBlueprint } = require('../helpers/blueprint'); |
| 14 | +const loadSafeBlueprintFile = require('../../src/load-safe-blueprint-file'); |
| 15 | + |
| 16 | +describe(stats, function() { |
| 17 | + this.timeout(5 * 60 * 1000); |
| 18 | + |
| 19 | + let cwd; |
| 20 | + let tmpPath; |
| 21 | + |
| 22 | + before(function() { |
| 23 | + cwd = process.cwd(); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(function() { |
| 27 | + process.chdir(cwd); |
| 28 | + }); |
| 29 | + |
| 30 | + async function merge({ |
| 31 | + blueprint, |
| 32 | + fixturesPath, |
| 33 | + commitMessage, |
| 34 | + beforeMerge = () => Promise.resolve() |
| 35 | + }) { |
| 36 | + tmpPath = await buildTmp({ |
| 37 | + fixturesPath, |
| 38 | + commitMessage |
| 39 | + }); |
| 40 | + |
| 41 | + await beforeMerge(); |
| 42 | + |
| 43 | + process.chdir(tmpPath); |
| 44 | + |
| 45 | + let promise = stats({ |
| 46 | + blueprint |
| 47 | + }); |
| 48 | + |
| 49 | + return await processExit({ |
| 50 | + promise, |
| 51 | + cwd: tmpPath, |
| 52 | + commitMessage, |
| 53 | + expect |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + it('works', async function() { |
| 58 | + let [ |
| 59 | + { |
| 60 | + packageName: packageName1, |
| 61 | + version: from1 |
| 62 | + }, |
| 63 | + { |
| 64 | + packageName: packageName2, |
| 65 | + location, |
| 66 | + version: from2 |
| 67 | + } |
| 68 | + ] = (await loadSafeBlueprintFile('test/fixtures/blueprint/app/local-app/local/my-app/config/ember-cli-update.json')).blueprints; |
| 69 | + |
| 70 | + let [ |
| 71 | + { |
| 72 | + version: to1 |
| 73 | + }, |
| 74 | + { |
| 75 | + version: to2 |
| 76 | + } |
| 77 | + ] = (await loadSafeBlueprintFile('test/fixtures/blueprint/app/local-app/merge/my-app/config/ember-cli-update.json')).blueprints; |
| 78 | + |
| 79 | + let { |
| 80 | + result, |
| 81 | + status |
| 82 | + } = await merge({ |
| 83 | + fixturesPath: 'test/fixtures/blueprint/app/local-app/local', |
| 84 | + commitMessage: 'my-app', |
| 85 | + async beforeMerge() { |
| 86 | + await initBlueprint({ |
| 87 | + fixturesPath: 'test/fixtures/blueprint/app/local', |
| 88 | + resolvedFrom: tmpPath, |
| 89 | + relativeDir: location |
| 90 | + }); |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + assertNoStaged(status); |
| 95 | + |
| 96 | + expect(result).to.equal(`${packageName1}, current: ${from1}, latest: ${to1} |
| 97 | +${packageName2}, current: ${from2}, latest: ${to2}`); |
| 98 | + }); |
| 99 | + |
| 100 | + it('handles missing blueprint', async function() { |
| 101 | + let { |
| 102 | + stderr, |
| 103 | + status |
| 104 | + } = await merge({ |
| 105 | + fixturesPath: 'test/fixtures/blueprint/app/local-app/local', |
| 106 | + commitMessage: 'my-app', |
| 107 | + blueprint: 'missing' |
| 108 | + }); |
| 109 | + |
| 110 | + assertNoStaged(status); |
| 111 | + |
| 112 | + expect(stderr).to.equal('blueprint "missing" was not found'); |
| 113 | + }); |
| 114 | +}); |
0 commit comments