Skip to content

Commit c025b8c

Browse files
Merge pull request #48 from ember-cli/split-tests-to-prove-self-imports-dont-work
Split build and test tests & fix self-imports (which splitting the tests proved the existence of a bug)
2 parents 79e4339 + 8ec440d commit c025b8c

3 files changed

Lines changed: 53 additions & 23 deletions

File tree

files/vite.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { extensions, ember } from '@embroider/vite';
33
import { babel } from '@rollup/plugin-babel';
44

55
export default defineConfig({
6+
resolve: {
7+
alias: [
8+
{
9+
find: '<%= name %>',
10+
replacement: `${__dirname}/src`,
11+
},
12+
],
13+
},
614
plugins: [
715
ember(),
816
babel({

tests/fixtures/addon/components/template-import.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class TemplateImport extends Component {
55
<template>
66
Hello from a GJS file
77

8-
<button {{on "click" this.saySomething}}></button>
8+
<button {{on "click" this.saySomething}} type="button"></button>
99
</template>
1010

1111
saySomething() {

tests/smoke-tests/defaults.test.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import path, { join } from 'node:path';
2+
import fs from 'node:fs/promises';
23

34
import tmp from 'tmp-promise';
45
let localEmberCli = require.resolve('ember-cli/bin/ember');
5-
import { beforeAll, describe, expect, it } from 'vitest';
6+
import { beforeEach, beforeAll, describe, expect, it } from 'vitest';
67
import { execa } from 'execa';
78
import fixturify from 'fixturify';
89

@@ -17,6 +18,14 @@ import {
1718
} from '../helpers.js';
1819
import { 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+
*/
2029
for (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

Comments
 (0)