Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type-tests #153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>();
6 changes: 6 additions & 0 deletions files/__addonLocation__/type-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"glint": {
"environment": "ember-loose"
},
}
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>();
14 changes: 12 additions & 2 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 +26,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 +36,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:types-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/**/*'],
},
});