|
1 | | -import path from 'node:path'; |
2 | | - |
| 1 | +import path, { join } from 'node:path'; |
| 2 | +import tmp from 'tmp-promise'; |
| 3 | +import fs from 'node:fs/promises'; |
| 4 | +import fixturify from 'fixturify'; |
3 | 5 | import { execa } from 'execa'; |
4 | | -import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
| 6 | +import { beforeAll, beforeEach, describe, expect, it } from 'vitest'; |
5 | 7 |
|
6 | | -import { |
7 | | - AddonHelper, |
8 | | - assertGeneratedCorrectly, |
9 | | - dirContents, |
10 | | - SUPPORTED_PACKAGE_MANAGERS, |
11 | | -} from '../helpers.js'; |
| 8 | +import { assertGeneratedCorrectly, dirContents, SUPPORTED_PACKAGE_MANAGERS } from '../helpers.js'; |
| 9 | +const blueprintPath = path.join(__dirname, '../..'); |
| 10 | +let localEmberCli = require.resolve('ember-cli/bin/ember'); |
12 | 11 |
|
13 | 12 | for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { |
14 | 13 | describe(`--typescript with ${packageManager}`, () => { |
15 | | - let distDir = ''; |
16 | | - let declarationsDir = ''; |
17 | | - let helper = new AddonHelper({ |
18 | | - packageManager, |
19 | | - args: ['--typescript'], |
20 | | - scenario: 'typescript', |
21 | | - }); |
| 14 | + let tmpDir: string; |
| 15 | + let addonDir: string; |
| 16 | + let addonName = 'my-addon'; |
22 | 17 |
|
23 | 18 | beforeAll(async () => { |
24 | | - await helper.setup(); |
25 | | - await helper.installDeps(); |
26 | | - |
27 | | - distDir = path.join(helper.projectRoot, 'dist'); |
28 | | - declarationsDir = path.join(helper.projectRoot, 'declarations'); |
| 19 | + tmpDir = (await tmp.dir()).path; |
| 20 | + addonDir = join(tmpDir, addonName); |
| 21 | + await execa({ |
| 22 | + cwd: tmpDir, |
| 23 | + })`${localEmberCli} addon ${addonName} -b ${blueprintPath} --skip-npm --skip-git --prefer-local true --${packageManager} --typescript`; |
| 24 | + await execa({ cwd: addonDir })`${packageManager} install`; |
29 | 25 | }); |
30 | 26 |
|
31 | 27 | it('was generated correctly', async () => { |
32 | | - await helper.build(); |
33 | | - |
34 | 28 | assertGeneratedCorrectly({ |
35 | | - projectRoot: helper.projectRoot, |
| 29 | + projectRoot: addonDir, |
36 | 30 | packageManager, |
37 | 31 | typeScript: true, |
38 | 32 | }); |
39 | 33 | }); |
40 | 34 |
|
41 | 35 | // Tests are additive, so when running them in order, we want to check linting |
42 | 36 | // before we add files from fixtures |
43 | | - it('lints all pass', async () => { |
44 | | - let { exitCode } = await helper.run('lint'); |
| 37 | + it('lints pass', async () => { |
| 38 | + let { exitCode } = await execa({ cwd: addonDir })`pnpm lint`; |
45 | 39 |
|
46 | 40 | expect(exitCode).toEqual(0); |
47 | 41 | }); |
48 | 42 |
|
49 | | - it('build and test', async () => { |
50 | | - // Copy over fixtures |
51 | | - await helper.fixtures.use('./src'); |
52 | | - await helper.fixtures.use('./tests'); |
53 | | - // Sync fixture with project's lint / formatting configuration |
54 | | - // (controlled by ember-cli) |
55 | | - // |
56 | | - // Ensure that we have no lint errors. |
57 | | - // It's important to keep this along with the tests, |
58 | | - // so that we can have confidence that the lints aren't destructively changing |
59 | | - // the files in a way that would break consumers |
60 | | - await helper.run('lint:fix'); |
61 | | - |
62 | | - let buildResult = await helper.build(); |
63 | | - |
64 | | - expect(buildResult.exitCode).toEqual(0); |
65 | | - |
66 | | - let distContents = await dirContents(distDir); |
67 | | - let declarationsContents = await dirContents(declarationsDir); |
68 | | - |
69 | | - expect(distContents).toMatchInlineSnapshot(` |
70 | | - [ |
71 | | - "_app_", |
72 | | - "components", |
73 | | - "index.js", |
74 | | - "index.js.map", |
75 | | - "services", |
76 | | - "template-registry.js", |
77 | | - "template-registry.js.map", |
78 | | - ] |
79 | | - `); |
80 | | - |
81 | | - expect(declarationsContents).toMatchInlineSnapshot(` |
82 | | - [ |
83 | | - "components", |
84 | | - "index.d.ts", |
85 | | - "index.d.ts.map", |
86 | | - "services", |
87 | | - "template-registry.d.ts", |
88 | | - "template-registry.d.ts.map", |
89 | | - ] |
90 | | - `); |
91 | | - |
92 | | - let testResult = await helper.run('test'); |
93 | | - |
94 | | - expect(testResult.exitCode).toEqual(0); |
95 | | - expect(testResult.stdout).to.include('# tests 5'); |
96 | | - expect(testResult.stdout).to.include('# pass 5'); |
97 | | - expect(testResult.stdout).to.include('# fail 0'); |
| 43 | + describe('with fixture', () => { |
| 44 | + beforeEach(async () => { |
| 45 | + let addonFixture = fixturify.readSync('./fixtures/addon'); |
| 46 | + fixturify.writeSync(join(addonDir, 'src'), addonFixture); |
| 47 | + |
| 48 | + let testFixture = fixturify.readSync('./fixtures/rendering-tests'); |
| 49 | + fixturify.writeSync(join(addonDir, 'tests/rendering'), testFixture); |
| 50 | + |
| 51 | + // It's important that we ensure that dist directory is empty for these tests, |
| 52 | + // troll-y things can happen with shared dists |
| 53 | + await fs.rm(join(addonDir, 'dist'), { recursive: true, force: true }); |
| 54 | + }); |
| 55 | + |
| 56 | + it('lint:fix', async () => { |
| 57 | + let { exitCode } = await execa({ cwd: addonDir })`${packageManager} run lint:fix`; |
| 58 | + |
| 59 | + expect(exitCode).toEqual(0); |
| 60 | + }); |
| 61 | + |
| 62 | + it('build', async () => { |
| 63 | + let buildResult = await execa({ cwd: addonDir })`${packageManager} run build`; |
| 64 | + |
| 65 | + expect(buildResult.exitCode).toEqual(0); |
| 66 | + |
| 67 | + let dist = await dirContents(join(addonDir, 'dist')); |
| 68 | + let declarations = await dirContents(join(addonDir, 'dist')); |
| 69 | + |
| 70 | + expect({ dist, declarations }).to.deep.equal({ |
| 71 | + dist: ['_app_', 'components', 'index.js', 'index.js.map'], |
| 72 | + declarations: [ |
| 73 | + 'components', |
| 74 | + 'index.d.ts', |
| 75 | + 'index.d.ts.map', |
| 76 | + 'services', |
| 77 | + 'template-registry.d.ts', |
| 78 | + 'template-registry.d.ts.map', |
| 79 | + ], |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + it('test', async () => { |
| 84 | + let testResult = await execa({ cwd: addonDir })`${packageManager} run test`; |
| 85 | + |
| 86 | + expect(testResult.exitCode).toEqual(0); |
| 87 | + |
| 88 | + expect(testResult.exitCode).toEqual(0); |
| 89 | + expect(testResult.stdout).to.include('# tests 5'); |
| 90 | + expect(testResult.stdout).to.include('# pass 5'); |
| 91 | + expect(testResult.stdout).to.include('# fail 0'); |
| 92 | + }); |
98 | 93 | }); |
99 | 94 | }); |
100 | 95 | } |
0 commit comments