Skip to content

Commit 4cf6fd1

Browse files
committed
Switch to inline snapshot for the files list
1 parent 30540e6 commit 4cf6fd1

4 files changed

Lines changed: 102 additions & 47 deletions

File tree

pnpm-lock.yaml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/helpers/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import assert from 'node:assert';
44
import path from 'node:path';
55
import { $ } from 'execa';
66
import { fileURLToPath } from 'node:url';
7+
import { globby } from 'globby';
78

89
import { execa, type Options } from 'execa';
910

@@ -106,6 +107,18 @@ export async function runScript({
106107
}
107108
}
108109

110+
export async function filesMatching(glob: string, dirPath: string) {
111+
try {
112+
let files = await globby(glob, { cwd: dirPath });
113+
114+
return files;
115+
} catch (e) {
116+
console.error('error', e);
117+
118+
return [];
119+
}
120+
}
121+
109122
export async function dirContents(dirPath: string) {
110123
try {
111124
let files = await fs.readdir(dirPath);

tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"execa": "^9.5.2",
1414
"fixturify": "^3.0.0",
1515
"fs-extra": "^10.0.0",
16+
"globby": "^14.1.0",
1617
"tmp-promise": "^3.0.3",
1718
"typescript": "^4.7.4",
1819
"vite": "^3.0.0",

tests/smoke-tests/--typescript.test.ts

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import fixturify from 'fixturify';
55
import { execa } from 'execa';
66
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
77

8-
import { assertGeneratedCorrectly, dirContents, SUPPORTED_PACKAGE_MANAGERS } from '../helpers.js';
8+
import {
9+
assertGeneratedCorrectly,
10+
dirContents,
11+
filesMatching,
12+
SUPPORTED_PACKAGE_MANAGERS,
13+
} from '../helpers.js';
914
const blueprintPath = path.join(__dirname, '../..');
1015
let localEmberCli = require.resolve('ember-cli/bin/ember');
1116

@@ -85,52 +90,48 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
8590
await commandSucceeds(`${packageManager} run build`);
8691

8792
expect(
88-
{
89-
src: await dirContents(join(addonDir, 'src')),
90-
// rollup output:
91-
dist: await dirContents(join(addonDir, 'dist')),
92-
'dist/components': await dirContents(join(addonDir, 'dist/components')),
93-
'dist/services': await dirContents(join(addonDir, 'dist/services')),
94-
// glint output:
95-
declarations: await dirContents(join(addonDir, 'declarations')),
96-
'declarations/components': await dirContents(join(addonDir, 'declarations/components')),
97-
'declarations/services': await dirContents(join(addonDir, 'declarations/services')),
98-
},
99-
`ensure we don't pollute the src dir with declarations and emit the js and .d.ts to the correct folders`,
100-
).to.deep.equal({
101-
src: ['components', 'index.ts', 'services', 'template-registry.ts'],
102-
dist: [
103-
'_app_',
104-
'components',
105-
'index.js',
106-
'index.js.map',
107-
'services',
108-
'template-registry.js',
109-
'template-registry.js.map',
110-
],
111-
'dist/components': [
112-
'another-gts.js',
113-
'another-gts.js.map',
114-
'template-import.js',
115-
'template-import.js.map',
116-
],
117-
'dist/services': ['example.js', 'example.js.map'],
118-
declarations: [
119-
'components',
120-
'index.d.ts',
121-
'index.d.ts.map',
122-
'services',
123-
'template-registry.d.ts',
124-
'template-registry.d.ts.map',
125-
],
126-
'declarations/components': [
127-
'another-gts.gts.d.ts',
128-
'another-gts.gts.d.ts.map',
129-
'template-import.gts.d.ts',
130-
'template-import.gts.d.ts.map',
131-
],
132-
'declarations/services': ['example.d.ts', 'example.d.ts.map'],
133-
});
93+
await filesMatching('src/**', addonDir),
94+
`ensure we don't pollute the src dir with declarations and emit the js and .d.ts to the correct folders -- this should be the same as the input files (no change from the fixture + default files)`,
95+
).toMatchInlineSnapshot(`
96+
[
97+
"src/index.ts",
98+
"src/template-registry.ts",
99+
"src/components/another-gts.gts",
100+
"src/components/template-import.gts",
101+
"src/services/example.ts",
102+
]
103+
`);
104+
105+
expect(
106+
await filesMatching('{dist,declarations}/**/*', addonDir),
107+
`ensure we emit the correct files out of the box to the correct folders`,
108+
).toMatchInlineSnapshot(`
109+
[
110+
"dist/index.js",
111+
"dist/index.js.map",
112+
"dist/template-registry.js",
113+
"dist/template-registry.js.map",
114+
"dist/components/another-gts.js",
115+
"dist/components/another-gts.js.map",
116+
"dist/components/template-import.js",
117+
"dist/components/template-import.js.map",
118+
"dist/services/example.js",
119+
"dist/services/example.js.map",
120+
"dist/_app_/components/another-gts.js",
121+
"dist/_app_/components/template-import.js",
122+
"dist/_app_/services/example.js",
123+
"declarations/index.d.ts",
124+
"declarations/index.d.ts.map",
125+
"declarations/template-registry.d.ts",
126+
"declarations/template-registry.d.ts.map",
127+
"declarations/components/another-gts.gts.d.ts",
128+
"declarations/components/another-gts.gts.d.ts.map",
129+
"declarations/components/template-import.gts.d.ts",
130+
"declarations/components/template-import.gts.d.ts.map",
131+
"declarations/services/example.d.ts",
132+
"declarations/services/example.d.ts.map",
133+
]
134+
`);
134135
});
135136

136137
it('test', async () => {

0 commit comments

Comments
 (0)