11'use strict' ;
22
3+ const path = require ( 'path' ) ;
34const { describe, it } = require ( '../helpers/mocha' ) ;
45const { expect } = require ( '../helpers/chai' ) ;
5- const { AddonTestApp } = require ( 'ember-cli-addon-tests' ) ;
66const {
7- gitInit,
8- commit : _commit ,
9- postCommit,
10- processIo,
7+ buildTmp,
8+ commit,
9+ processBin,
1110 fixtureCompare : _fixtureCompare
1211} = require ( 'git-fixtures' ) ;
13- const { run } = require ( 'git-diff-apply' ) ;
1412const {
1513 assertNormalUpdate,
1614 assertNoUnstaged
1715} = require ( '../helpers/assertions' ) ;
18- const { promisify } = require ( 'util' ) ;
19- const cpr = promisify ( require ( 'cpr' ) ) ;
20-
21- const commitMessage = 'add files' ;
22-
23- async function reset ( tmpPath ) {
24- await run ( 'git rm -r .' , { cwd : tmpPath } ) ;
25-
26- await cpr ( 'test/fixtures/app/local/my-app' , tmpPath ) ;
27- }
28-
29- async function init ( tmpPath ) {
30- await gitInit ( {
31- cwd : tmpPath
32- } ) ;
33-
34- await _commit ( {
35- cwd : tmpPath
36- } ) ;
37- }
38-
39- async function commit ( tmpPath ) {
40- await _commit ( {
41- m : commitMessage ,
42- cwd : tmpPath
43- } ) ;
44-
45- await postCommit ( {
46- cwd : tmpPath
16+ const run = require ( '../../src/run' ) ;
17+ const replaceFile = require ( 'boilerplate-update/src/replace-file' ) ;
18+ const { EOL } = require ( 'os' ) ;
19+
20+ async function mutatePackageJson ( cwd , callback ) {
21+ await replaceFile ( path . join ( cwd , 'package.json' ) , file => {
22+ let pkg = JSON . parse ( file ) ;
23+ callback ( pkg ) ;
24+ return JSON . stringify ( pkg , null , 2 ) . replace ( / \n / g, EOL ) + EOL ;
4725 } ) ;
4826}
4927
5028describe ( function ( ) {
51- this . timeout ( 10 * 60 * 1000 ) ;
52-
53- let app ;
54-
55- beforeEach ( async function ( ) {
56- app = new AddonTestApp ( ) ;
57-
58- await app . create ( 'my-app' , {
59- fixturesPath : 'test/fixtures/app/local' ,
60- skipNpm : true
61- } ) ;
29+ this . timeout ( 3 * 60 * 1000 ) ;
6230
63- await init ( app . path ) ;
31+ let tmpPath ;
6432
65- // remove newer fixture files not present in older versions
66- await reset ( app . path ) ;
67-
68- app . editPackageJSON ( pkg => {
69- pkg . devDependencies [ 'ember-cli-update' ] = '*' ;
33+ async function merge ( {
34+ fixturesPath,
35+ to = '3.11.0-beta.1' ,
36+ commitMessage,
37+ beforeMerge = ( ) => Promise . resolve ( )
38+ } ) {
39+ tmpPath = await buildTmp ( {
40+ fixturesPath
7041 } ) ;
7142
72- await commit ( app . path ) ;
73-
74- await app . run ( 'npm' , 'install' , '--no-package-lock' ) ;
43+ await beforeMerge ( ) ;
7544
76- await app . startServer ( {
77- command : 'update ' ,
78- additionalArguments : [
79- '--to ' ,
80- '3.11.0-beta.1' ,
45+ return await ( await processBin ( {
46+ bin : 'ember ' ,
47+ args : [
48+ 'update ' ,
49+ `--to= ${ to } ` ,
8150 '--resolve-conflicts'
8251 ] ,
83- detectServerStart ( ) {
84- return true ;
85- }
86- } ) ;
87- } ) ;
52+ cwd : tmpPath ,
53+ commitMessage ,
54+ expect
55+ } ) ) . promise ;
56+ }
8857
8958 function fixtureCompare ( {
59+ actual = tmpPath ,
9060 mergeFixtures
9161 } ) {
92- let actual = app . path ;
9362 let expected = mergeFixtures ;
9463
9564 _fixtureCompare ( {
@@ -99,22 +68,28 @@ describe(function() {
9968 } ) ;
10069 }
10170
102- async function merge ( ) {
103- return await processIo ( {
104- ps : app . server ,
105- cwd : app . path ,
106- commitMessage,
107- expect
108- } ) ;
109- }
110-
11171 it ( 'works' , async function ( ) {
11272 let {
11373 status
114- } = await merge ( ) ;
74+ } = await merge ( {
75+ fixturesPath : 'test/fixtures/app/local' ,
76+ commitMessage : 'my-app' ,
77+ async beforeMerge ( ) {
78+ await mutatePackageJson ( tmpPath , pkg => {
79+ pkg . devDependencies [ 'ember-cli-update' ] = '*' ;
80+ } ) ;
81+
82+ await run ( 'npm install --no-package-lock' , { cwd : tmpPath } ) ;
83+
84+ await commit ( {
85+ m : 'my-app' ,
86+ cwd : tmpPath
87+ } ) ;
88+ }
89+ } ) ;
11590
11691 // remove addon because it's not in the fixtures
117- app . editPackageJSON ( pkg => {
92+ await mutatePackageJson ( tmpPath , pkg => {
11893 delete pkg . devDependencies [ 'ember-cli-update' ] ;
11994 } ) ;
12095
0 commit comments