Skip to content

Commit

Permalink
Add type-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jul 17, 2023
1 parent 11cc6c5 commit a6fc51f
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion files/__addonLocation__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js:fix": "eslint . --fix",<% if (typescript) { %>
"lint:types": "glint",
"lint:types-tests": "glint --project type-tests",
"start": "concurrently 'npm:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "glint --declaration --watch",<% } else { %>
Expand Down Expand Up @@ -73,7 +74,8 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^11.6.0",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^4.0.0",<% if (typescript) { %>
"expect-type": "^0.16.0",<% } %>
"prettier": "^2.5.1",
"rollup": "^3.21.8"<% if (!isExistingMonorepo) { %>,
"rollup-plugin-copy": "^3.4.0"<% } %><% if (typescript) { %>,
Expand Down
2 changes: 1 addition & 1 deletion files/__addonLocation__/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"environment": "ember-loose"
},
"compilerOptions": {
"declarationDir": "declarations"
"declarationDir": "declarations",
}
}
4 changes: 4 additions & 0 deletions files/__addonLocation__/type-tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expectTypeOf } from 'expect-type';

// Replace this with your real type tests
expectTypeOf(1).toEqualTypeOf<number>();
3 changes: 3 additions & 0 deletions files/__addonLocation__/type-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/ember/tsconfig.json"
}
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ module.exports = {
files = files.filter(
(filename) => !filename.match(/.*\.ts$/) && !ignoredFiles.includes(filename)
);

files = files.filter((filename) => !filename.includes('type-tests'));
}

if (this.isExistingMonorepo) {
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/addon-only-ts/type-tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expectTypeOf } from 'expect-type';

// Replace this with your real type tests
expectTypeOf(1).toEqualTypeOf<number>();
15 changes: 12 additions & 3 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { execa } from 'execa';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import {
AddonHelper,
Expand All @@ -13,6 +12,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
describe(`--typescript with ${packageManager}`, () => {
let distDir = '';
let declarationsDir = '';
let typeTestsDir = '';
let helper = new AddonHelper({
packageManager,
args: ['--typescript'],
Expand All @@ -25,6 +25,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {

distDir = path.join(helper.addonFolder, 'dist');
declarationsDir = path.join(helper.addonFolder, 'declarations');
typeTestsDir = path.join(helper.addonFolder, 'type-tests');
});

afterAll(async () => {
Expand All @@ -34,15 +35,23 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
it('was generated correctly', async () => {
await helper.build();

assertGeneratedCorrectly({ projectRoot: helper.projectRoot });
await assertGeneratedCorrectly({ projectRoot: helper.projectRoot });

let contents = await dirContents(helper.addonFolder);

expect(contents).to.include('type-tests');
expect(contents).to.include('tsconfig.json');

expect(await dirContents(typeTestsDir)).to.deep.equal(['index.test.ts', 'tsconfig.json']);
});

// Tests are additive, so when running them in order, we want to check linting
// before we add files from fixtures
it('lints all pass', async () => {
let { exitCode } = await helper.run('lint');
let { exitCode, stdout } = await helper.run('lint');

expect(exitCode).toEqual(0);
expect(stdout).to.include('lint:type-tests');
});

it('build and test', async () => {
Expand Down
7 changes: 6 additions & 1 deletion tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
});

it('was generated correctly', async () => {
assertGeneratedCorrectly({ projectRoot: helper.projectRoot });
await assertGeneratedCorrectly({ projectRoot: helper.projectRoot });

let contents = await dirContents(helper.addonFolder);

expect(contents).to.not.include('type-tests');
expect(contents).to.not.include('tsconfig.json');
});

// Tests are additive, so when running them in order, we want to check linting
Expand Down
1 change: 1 addition & 0 deletions tests/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default defineConfig({
test: {
testTimeout: 60 * ONE_SECOND,
hookTimeout: 150 * ONE_SECOND,
exclude: ['fixtures/**/*'],
},
});

0 comments on commit a6fc51f

Please sign in to comment.