Skip to content

Commit

Permalink
opt for type:module in TS API app test suite (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmason2-godaddy authored Nov 15, 2024
1 parent ff3acd0 commit 1055c19
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest, describe, beforeEach, it, expect } from '@jest/globals';
import { defaultHandler } from '../routes';

describe('Routes', () => {
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/gasket-plugin-express/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = async function create(gasket, context) {
});

if (apiApp && addApiRoutes) {
const globIgnore = typescript ? '!(*.js)' : '!(*.ts|*.json)';
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
files.add(`${generatorDir}/app/**/${globIgnore}`);

createTestFiles({ files, generatorDir, testPlugins, globIgnore });
Expand Down
10 changes: 5 additions & 5 deletions packages/gasket-plugin-express/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('create', () => {
it('respects the typescript flag', async () => {
mockContext.typescript = false;
await expectCreatedWith(({ files }) => {
expect(files.add).toHaveBeenCalledWith(expect.stringContaining('../generator/app/**/!(*.ts|*.json)'));
expect(files.add).toHaveBeenCalledWith(expect.stringContaining('../generator/app/**/!(*.ts)'));
})();
mockContext.typescript = true;
await expectCreatedWith(({ files }) => {
Expand All @@ -233,8 +233,8 @@ describe('create', () => {
mockContext.testPlugins = ['@gasket/mocha'];
await expectCreatedWith(({ files }) => {
expect(files.add).toHaveBeenCalledWith(
expect.stringContaining(`/generator/mocha/*/!(*.ts|*.json)`),
expect.stringContaining(`/generator/mocha/**/!(*.ts|*.json)`)
expect.stringContaining(`/generator/mocha/*/!(*.ts)`),
expect.stringContaining(`/generator/mocha/**/!(*.ts)`)
);
})();
});
Expand All @@ -243,8 +243,8 @@ describe('create', () => {
mockContext.testPlugins = ['@gasket/jest'];
await expectCreatedWith(({ files }) => {
expect(files.add).toHaveBeenCalledWith(
expect.stringContaining(`/generator/jest/*/!(*.ts|*.json)`),
expect.stringContaining(`/generator/jest/**/!(*.ts|*.json)`)
expect.stringContaining(`/generator/jest/*/!(*.ts)`),
expect.stringContaining(`/generator/jest/**/!(*.ts)`)
);
})();
});
Expand Down
3 changes: 2 additions & 1 deletion packages/gasket-plugin-jest/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ const plugin = {
if (typescript) {
pkg.add('devDependencies', {
'@types/jest': devDependencies['@types/jest'],
'cross-env': devDependencies['cross-env'],
'ts-jest': devDependencies['ts-jest'],
'ts-node': devDependencies['ts-node']
});

pkg.add('scripts', {
'test': 'TS_NODE_PROJECT=./tsconfig.test.json jest',
'test': "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
'test:watch': 'npm run test -- --watchAll',
'test:coverage': 'npm run test -- --coverage'
});
Expand Down
12 changes: 11 additions & 1 deletion packages/gasket-plugin-jest/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,20 @@ describe('Plugin', function () {
expect(pkg.devDependencies['ts-jest']).toEqual(devDependencies['ts-jest']);
expect(pkg.devDependencies['ts-node']).toEqual(devDependencies['ts-node']);
expect(pkg.scripts).toEqual({
'test': 'TS_NODE_PROJECT=./tsconfig.test.json jest',
'test': "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
'test:watch': 'npm run test -- --watchAll',
'test:coverage': 'npm run test -- --coverage'
});
});

it('adds devDeps for apiApp with typescript', async function () {
mockContext.typescript = true;
const { pkg } = await create(mockContext);

expect(pkg.devDependencies['cross-env']).toEqual(devDependencies['cross-env']);
expect(pkg.devDependencies['@types/jest']).toEqual(devDependencies['@types/jest']);
expect(pkg.devDependencies['ts-jest']).toEqual(devDependencies['ts-jest']);
expect(pkg.devDependencies['ts-node']).toEqual(devDependencies['ts-node']);
});
});
});

0 comments on commit 1055c19

Please sign in to comment.