11import path , { join } from 'node:path' ;
2+ import fs from 'node:fs/promises' ;
23
34import tmp from 'tmp-promise' ;
45let localEmberCli = require . resolve ( 'ember-cli/bin/ember' ) ;
5- import { beforeAll , describe , expect , it } from 'vitest' ;
6+ import { beforeEach , beforeAll , describe , expect , it } from 'vitest' ;
67import { execa } from 'execa' ;
78import fixturify from 'fixturify' ;
89
@@ -17,6 +18,14 @@ import {
1718} from '../helpers.js' ;
1819import { existsSync } from 'node:fs' ;
1920
21+ /**
22+ * NOTE: tests run sequentially
23+ * we need to manually specify "concurrent" to run them in parallel
24+ *
25+ * https://vitest.dev/guide/features.html#running-tests-concurrently
26+ *
27+ * This is important because we delete stuff in one test that was created in another
28+ */
2029for ( let packageManager of SUPPORTED_PACKAGE_MANAGERS ) {
2130 describe ( `defaults with ${ packageManager } ` , ( ) => {
2231 let tmpDir : string ;
@@ -94,43 +103,56 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
94103 expect ( exitCode ) . toEqual ( 0 ) ;
95104 } ) ;
96105
97- it ( 'build and test' , async ( ) => {
98- let addonFixture = fixturify . readSync ( './fixtures/addon' ) ;
99- fixturify . writeSync ( join ( addonDir , 'src' ) , addonFixture ) ;
100-
101- let testFixture = fixturify . readSync ( './fixtures/rendering-tests' ) ;
102- fixturify . writeSync ( join ( addonDir , 'tests/rendering' ) , testFixture ) ;
103-
104- // Ensure that we have no lint errors.
105- // It's important to keep this along with the tests,
106- // so that we can have confidence that the lints aren't destructively changing
107- // the files in a way that would break consumers
106+ it ( 'lint:fix with no fixtures' , async ( ) => {
108107 let { exitCode } = await execa ( { cwd : addonDir } ) `${ packageManager } run lint:fix` ;
109108
110109 expect ( exitCode ) . toEqual ( 0 ) ;
110+ } ) ;
111111
112- let buildResult = await execa ( { cwd : addonDir } ) `${ packageManager } run build` ;
112+ describe ( 'with fixture' , ( ) => {
113+ beforeEach ( async ( ) => {
114+ let addonFixture = fixturify . readSync ( './fixtures/addon' ) ;
115+ fixturify . writeSync ( join ( addonDir , 'src' ) , addonFixture ) ;
113116
114- expect ( buildResult . exitCode ) . toEqual ( 0 ) ;
117+ let testFixture = fixturify . readSync ( './fixtures/rendering-tests' ) ;
118+ fixturify . writeSync ( join ( addonDir , 'tests/rendering' ) , testFixture ) ;
119+ } ) ;
115120
116- let contents = await dirContents ( join ( addonDir , 'dist' ) ) ;
121+ it ( 'lint:fix' , async ( ) => {
122+ let { exitCode } = await execa ( { cwd : addonDir } ) `${ packageManager } run lint:fix` ;
123+
124+ expect ( exitCode ) . toEqual ( 0 ) ;
125+ } ) ;
126+
127+ it ( 'build' , async ( ) => {
128+ let buildResult = await execa ( { cwd : addonDir } ) `${ packageManager } run build` ;
129+
130+ expect ( buildResult . exitCode ) . toEqual ( 0 ) ;
131+
132+ let contents = await dirContents ( join ( addonDir , 'dist' ) ) ;
133+
134+ expect ( contents ) . to . deep . equal ( [ '_app_' , 'components' , 'index.js' , 'index.js.map' ] ) ;
135+ } ) ;
117136
118- expect ( contents ) . to . deep . equal ( [ '_app_' , 'components' , 'index.js' , 'index.js.map' ] ) ;
137+ it ( 'test' , async ( ) => {
138+ // It's important that we ensure that dist directory is empty for this test, because
139+ await fs . rm ( join ( addonDir , 'dist' ) , { recursive : true , force : true } ) ;
119140
120- let testResult = await await execa ( { cwd : addonDir } ) `${ packageManager } run test` ;
141+ let testResult = await execa ( { cwd : addonDir } ) `${ packageManager } run test` ;
121142
122- expect ( testResult . exitCode ) . toEqual ( 0 ) ;
143+ expect ( testResult . exitCode ) . toEqual ( 0 ) ;
123144
124- expect ( testResult . stdout ) . includes (
125- `# tests 2
145+ expect ( testResult . stdout ) . includes (
146+ `# tests 2
126147# pass 2
127148# skip 0
128149# todo 0
129150# fail 0
130151
131152# ok` ,
132- testResult . stdout ,
133- ) ;
153+ testResult . stdout ,
154+ ) ;
155+ } ) ;
134156 } ) ;
135157 } ) ;
136158}
0 commit comments