Skip to content

Commit 5a802d4

Browse files
committed
Fix jest tests
1 parent 8b5e0df commit 5a802d4

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

js/cli/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function updateConfigVersions() {
2525
config.versions['polkadot-api'] = sailsJs.peerDependencies['@polkadot/api'];
2626
config.versions['sails-js'] = sailsJs.version;
2727
config.versions['typescript'] = rootPkgJson.devDependencies.typescript;
28+
config.versions['@gear-js/react-hooks'] = sailsJs.devDependencies['@gear-js/react-hooks'];
2829

2930
writeFileSync('src/config.json', JSON.stringify(config, null, 2));
3031
},

js/jest.config.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
import type { Config } from '@jest/types';
2-
import { createDefaultEsmPreset } from 'ts-jest';
32

43
const config: Config.InitialOptions = {
5-
...createDefaultEsmPreset(),
64
globalSetup: './test/setup.js',
75
clearMocks: true,
86
coverageProvider: 'v8',
97
testEnvironment: 'node',
108
verbose: true,
11-
9+
preset: 'ts-jest/presets/js-with-babel',
10+
transformIgnorePatterns: ['node_modules/(?!@polkadot)/'],
11+
extensionsToTreatAsEsm: ['.ts'],
1212
moduleNameMapper: {
1313
'^(\\.{1,2}/.*)\\.js$': '$1',
14-
15-
// manually resolving hooks to esm, cuz somehow jest resolves it to cjs?
16-
// if main property in a package.json is pointing to esm, there's no problem whatsoever.
17-
// maybe it has something to do with the package folder structure
18-
'^@gear-js/react-hooks$': '<rootDir>/../node_modules/@gear-js/react-hooks/dist/esm/index.mjs',
1914
},
20-
21-
testTimeout: 15_000,
22-
23-
// cuz hooks testEnvironment is jsdom. there was a problem with rxjs for example
24-
// https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149
25-
// https://jest-archive-august-2023.netlify.app/docs/28.x/upgrading-to-jest28/#packagejson-exports
26-
testEnvironmentOptions: {
27-
customExportConditions: ['node'],
15+
transform: {
16+
'^.+\\.tsx?$': ['ts-jest', { useESM: true }],
2817
},
18+
testTimeout: 15_000,
19+
testPathIgnorePatterns: ['demo-hooks.test.tsx'], // ignore hooks test
2920
};
3021

3122
export default config;

js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"scripts": {
3333
"prebuild": "rm -rf lib",
3434
"build": "npx rollup --config rollup.config.js",
35-
"test": "yarn node --no-warnings --experimental-vm-modules $(yarn bin jest) --detectOpenHandles",
36-
"test-hooks": "vitest"
35+
"test-hooks": "vitest",
36+
"test": "yarn node --no-warnings --experimental-vm-modules $(yarn bin jest) --detectOpenHandles && yarn run test-hooks"
3737
},
3838
"peerDependencies": {
3939
"@gear-js/api": "0.38.2",

js/vitest.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { defineConfig } from 'vitest/config';
33
export default defineConfig({
44
// resolving manually cuz vitest is using nodejs resolution, remove after hooks update
55
// https://github.com/vitest-dev/vitest/discussions/4233
6-
resolve: { alias: { '@gear-js/react-hooks': '@gear-js/react-hooks/dist/esm/index.mjs' } },
6+
resolve: {
7+
alias: {
8+
'@gear-js/react-hooks': '@gear-js/react-hooks/dist/esm/index.mjs',
9+
},
10+
},
711

812
test: {
9-
// globalSetup: 'test/setup.js',
1013
include: ['**/*-hooks.test.ts?(x)'], // targeting only hooks
1114
environment: 'happy-dom', // faster than jsdom
1215
watch: false, // fire one time

0 commit comments

Comments
 (0)