Skip to content

Commit 9afec9b

Browse files
author
David Enke
committed
chore: make tests great again
1 parent 5d4f59b commit 9afec9b

7 files changed

Lines changed: 36 additions & 21 deletions

File tree

globals.d.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ declare module '@custom-elements-manifest/to-markdown' {
1515
): string;
1616
}
1717

18-
declare module '@custom-elements-manifest/analyzer/browser/index.js' {
18+
declare module '@custom-elements-manifest/analyzer/index.js' {
1919
import type { Plugin } from '@custom-elements-manifest/analyzer';
2020
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2121
const create: (options: { modules: any[]; plugins: Plugin[]; context: { dev: boolean } }) => any;
2222
const ts: typeof import('typescript');
23-
const litPlugin: () => Plugin[];
24-
export { create, litPlugin, ts };
23+
24+
export { create, ts };
25+
}
26+
27+
declare module '@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js' {
28+
import type { Plugin } from '@custom-elements-manifest/analyzer';
29+
30+
export const litPlugin: () => Plugin[];
2531
}
2632

2733
declare module 'esbuild-copy-static-files' {
@@ -41,3 +47,11 @@ declare module 'esbuild-copy-static-files' {
4147
const copyStaticFiles: (options?: Partial<CopyStaticFilesOptions>) => Plugin;
4248
export default copyStaticFiles;
4349
}
50+
51+
declare module '@remcovaes/web-test-runner-vite-plugin' {
52+
import type { TestRunnerCoreConfig, TestRunnerPlugin } from '@web/test-runner-core';
53+
import type { UserConfig } from 'vite';
54+
55+
export function vitePlugin(config?: UserConfig): TestRunnerPlugin;
56+
export const removeViteLogging: TestRunnerCoreConfig['filterBrowserLogs'];
57+
}

jest.config.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { JestConfigWithTsJest } from 'ts-jest';
2+
import { createDefaultEsmPreset } from 'ts-jest';
23

3-
// Sync object
4-
const config: JestConfigWithTsJest = {
5-
extensionsToTreatAsEsm: ['.ts'],
6-
preset: 'ts-jest/presets/default-esm',
7-
testEnvironment: 'node',
8-
testMatch: ['<rootDir>/src/**/*(*.)@(spec|test).[tj]s'],
9-
testPathIgnorePatterns: ['/node_modules/'],
4+
const esmPreset = createDefaultEsmPreset({ tsconfig: 'tsconfig.json' });
5+
const jestConfig: JestConfigWithTsJest = {
6+
...esmPreset,
7+
// Typescript imports as `*.js` must be mapped manually
8+
// https://github.com/swc-project/jest/issues/64
9+
// https://stackoverflow.com/a/75833026/1146207
10+
moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': '$1' },
11+
// Somehow we need to specify the transform for ESM files
1012
transform: { '^.+\\.m?[tj]sx?$': ['ts-jest', { useESM: true }] },
1113
transformIgnorePatterns: ['<rootDir>/node_modules/(?!(@custom-elements-manifest|@github|cem-plugins))'],
12-
moduleFileExtensions: ['js', 'mjs', 'cjs', 'jsx', 'd.ts', 'ts', 'tsx', 'json', 'node'],
1314
};
1415

15-
export default config;
16+
export default jestConfig;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"jest-junit": {
5252
"outputDirectory": "reports",
53-
"outputName": "test-unit.xml",
53+
"outputName": "test.junit.xml",
5454
"usePathForSuiteName": true
5555
}
5656
}

src/cem-plugin-examples/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { readFile } from 'node:fs/promises';
22
import { join, resolve } from 'node:path';
33

4-
// https://custom-elements-manifest.open-wc.org/analyzer/getting-started/#usage-in-the-browser
5-
import { create, litPlugin, ts } from '@custom-elements-manifest/analyzer/browser/index.js';
4+
import { create, ts } from '@custom-elements-manifest/analyzer/index.js';
5+
import { litPlugin } from '@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js';
66
import type { SourceFile } from 'typescript';
77

88
import { customElementExamplesPlugin } from './index.js';

src/cem-plugin-generate-readmes/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { existsSync } from 'node:fs';
22
import { readFile, rm, writeFile } from 'node:fs/promises';
33
import { join, resolve } from 'node:path';
44

5-
// https://custom-elements-manifest.open-wc.org/analyzer/getting-started/#usage-in-the-browser
6-
import { create, litPlugin, ts } from '@custom-elements-manifest/analyzer/browser/index.js';
5+
import { create, ts } from '@custom-elements-manifest/analyzer/index.js';
6+
import { litPlugin } from '@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js';
77
import type { SourceFile } from 'typescript';
88

99
import { customElementGenerateReadmesPlugin } from './index.js';

src/cem-plugin-grouping/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { readFile } from 'node:fs/promises';
22
import { join, resolve } from 'node:path';
33

4-
// https://custom-elements-manifest.open-wc.org/analyzer/getting-started/#usage-in-the-browser
5-
import { create, litPlugin, ts } from '@custom-elements-manifest/analyzer/browser/index.js';
4+
import { create, ts } from '@custom-elements-manifest/analyzer/index.js';
5+
import { litPlugin } from '@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js';
66

77
import { customElementGroupingPlugin } from './index.js';
88

src/cem-plugin-inline-readme/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { readFile } from 'node:fs/promises';
22
import { join, resolve } from 'node:path';
33

4-
// https://custom-elements-manifest.open-wc.org/analyzer/getting-started/#usage-in-the-browser
5-
import { create, litPlugin, ts } from '@custom-elements-manifest/analyzer/browser/index.js';
4+
import { create, ts } from '@custom-elements-manifest/analyzer/index.js';
5+
import { litPlugin } from '@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js';
66

77
import { customElementInlineReadmePlugin } from './index.js';
88

0 commit comments

Comments
 (0)