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 15, 2023
1 parent 3852609 commit f0a67e5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 7 deletions.
3 changes: 2 additions & 1 deletion files/__addonLocation__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,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
3 changes: 2 additions & 1 deletion files/__addonLocation__/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "@tsconfig/ember/tsconfig.json",
"include": [
"src/**/*",
"unpublished-development-types/**/*"
"unpublished-development-types/**/*",
"type-tests/**/*"
],
"glint": {
"environment": "ember-loose"
Expand Down
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>();
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>();
42 changes: 39 additions & 3 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { assertGeneratedCorrectly } from '../assertions.js';
import { assertGeneratedCorrectly, matchesFixture } from '../assertions.js';
import {
createAddon,
createTmp,
Expand All @@ -18,6 +18,8 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
let tmpDir = '';
let distDir = '';
let declarationsDir = '';
let typeTests = '';
let addonDir = '';

beforeAll(async () => {
tmpDir = await createTmp();
Expand All @@ -28,27 +30,61 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
});

cwd = path.join(tmpDir, name);
addonDir = path.join(cwd, name);
typeTests = path.join(cwd, name, 'type-tests');
distDir = path.join(cwd, name, 'dist');
declarationsDir = path.join(cwd, name, 'declarations');

await install({ cwd, packageManager, skipPrepare: true });
});

afterAll(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
// await fs.rm(tmpDir, { recursive: true, force: true });
});

it('was generated correctly', async () => {
await runScript({ cwd, script: 'build', packageManager: 'pnpm' });

assertGeneratedCorrectly({ projectRoot: cwd });
await assertGeneratedCorrectly({ projectRoot: cwd });

let addonContents = await dirContents(addonDir);

expect(addonContents).to.deep.equal([
'.eslintignore',
'.eslintrc.cjs',
'.gitignore',
'.prettierignore',
'.prettierrc.js',
'.template-lintrc.cjs',
'LICENSE.md',
'README.md',
'addon-main.cjs',
'babel.config.json',
'declarations',
'dist',
'node_modules',
'package.json',
'rollup.config.mjs',
'src',
'tsconfig.json',
'type-tests',
'unpublished-development-types',
]);

await matchesFixture(path.join(typeTests, 'index.test.ts'), {
cwd,
scenario: 'addon-only-ts',
file: 'type-tests/index.test.ts',
});
});

it('builds the addon', async () => {
let { exitCode } = await runScript({ cwd, script: 'build', packageManager: 'pnpm' });

expect(exitCode).toEqual(0);

console.log({ distDir, declarationsDir });

let distContents = await dirContents(distDir);
let declarationsContents = await dirContents(declarationsDir);

Expand Down
9 changes: 8 additions & 1 deletion tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
let cwd = '';
let tmpDir = '';
let distDir = '';
let addonDir = '';

beforeAll(async () => {
tmpDir = await createTmp();
Expand All @@ -30,6 +31,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
});

cwd = path.join(tmpDir, name);
addonDir = path.join(cwd, name);
distDir = path.join(cwd, name, 'dist');

await install({ cwd, packageManager });
Expand Down Expand Up @@ -79,7 +81,12 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
});

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

let contents = await dirContents(addonDir);

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

it('builds the addon', async () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

// Vite's internal types aren't relevant to us
"skipLibCheck": true
}
},
"exclude": ["fixtures/"]
}
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 f0a67e5

Please sign in to comment.