Skip to content

Commit a5827d5

Browse files
committed
Make the typescript tests more similar to the default tests
1 parent 3414f2f commit a5827d5

6 files changed

Lines changed: 85 additions & 83 deletions

File tree

files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@babel/plugin-transform-typescript": "^7.25.2",<% } %>
3939
"@babel/runtime": "^7.25.6",
4040
"@ember/test-helpers": "^5.2.1",
41-
"@embroider/addon-dev": "^8.0.1",
41+
"@embroider/addon-dev": "^8.1.0",
4242
"@embroider/core": "^4.1.0",
4343
"@embroider/compat": "^4.1.0",
4444
"@embroider/macros": "^1.18.0",

files/rollup.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export default {
6363
addon.gjs(),<% if (typescript) { %>
6464

6565
// Emit .d.ts declaration files
66-
addon.declarations('declarations', `<%= packageManager %> exec glint --declaration --project ${configs.ts}`),<% } %>
66+
addon.declarations(
67+
'declarations',
68+
`<%= packageManager %> exec glint --declaration --project ${configs.ts}`
69+
),<% } %>
6770

6871
// addons are allowed to contain imports of .css files, which we want rollup
6972
// to leave alone and keep in the published output.

files/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"glint": {
99
"environment": ["ember-loose", "ember-template-imports"]
1010
},
11-
"include": ["src", "tests", "unpublished-development-types"],
11+
"include": ["src/**/*", "tests/**/*", "unpublished-development-types/**/*"],
1212
"compilerOptions": {
1313
"rootDir": ".",
1414
"types": [

files/tsconfig.publish.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "@ember/library-tsconfig",
3-
"include": ["src", "unpublished-development-types"],
3+
"include": ["src/**/*", "unpublished-development-types/**/*"],
44
"glint": {
55
"environment": ["ember-loose", "ember-template-imports"]
66
},
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { tracked, cached } from '@glimmer/tracking';
22
import Component from '@glimmer/component';
33
import Route from '@ember/routing/route';
4-
import { uniqueId } from '@ember/utils';
4+
import { isPresent } from '@ember/utils';
55

6-
export const everythingHasTypes = {
7-
tracked, cached, Component, Route, uniqueId
8-
}
6+
console.log({
7+
tracked,
8+
cached,
9+
Component,
10+
Route,
11+
isPresent,
12+
});
Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,95 @@
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';
35
import { execa } from 'execa';
4-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
6+
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
57

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');
1211

1312
for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
1413
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';
2217

2318
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`;
2925
});
3026

3127
it('was generated correctly', async () => {
32-
await helper.build();
33-
3428
assertGeneratedCorrectly({
35-
projectRoot: helper.projectRoot,
29+
projectRoot: addonDir,
3630
packageManager,
3731
typeScript: true,
3832
});
3933
});
4034

4135
// Tests are additive, so when running them in order, we want to check linting
4236
// 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`;
4539

4640
expect(exitCode).toEqual(0);
4741
});
4842

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+
});
9893
});
9994
});
10095
}

0 commit comments

Comments
 (0)