Skip to content

Commit 28646e6

Browse files
committed
Update jest and get cli tests running again
1 parent 74820cc commit 28646e6

File tree

7 files changed

+1566
-812
lines changed

7 files changed

+1566
-812
lines changed

jest.config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ module.exports = {
8181
// An array of file extensions your modules use
8282

8383
moduleFileExtensions: ['js', 'json', 'ts'],
84+
// extensionsToTreatAsEsm: ['.ts'],
8485

8586
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
8687
// moduleNameMapper: {},
@@ -95,6 +96,7 @@ module.exports = {
9596
'^@subql/types-core/(.*)$': '<rootDir>/packages/types-core/src/$1',
9697
'^@subql/utils$': '<rootDir>/packages/utils/src/',
9798
'^@subql/utils/(.*)$': '<rootDir>/packages/utils/src/$1',
99+
'^(\\.{1,2}/.*)\\.js$': '$1', // For ESM packages (CLI)
98100
},
99101

100102
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
@@ -191,10 +193,20 @@ module.exports = {
191193

192194
// A map from regular expressions to paths to transformers
193195
transform: {
194-
'^.+\\.(ts|tsx)?$': [
196+
// ESM package (CLI)
197+
'^.+\\.(t|j)sx?$': [
195198
'ts-jest',
196199
{
197-
tsconfig: 'tsconfig.test.json',
200+
useESM: true,
201+
tsconfig: '<rootDir>/packages/cli/tsconfig.json',
202+
},
203+
],
204+
// Fallback for everything else (CJS)
205+
// Important: this must come last because regex order matters
206+
'^(?!.*packages/cli).*\\.(t|j)sx?$': [
207+
'ts-jest',
208+
{
209+
useESM: false,
198210
},
199211
],
200212
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"eslint-plugin-prettier": "^5.1.3",
2020
"eslint-plugin-sort-destructure-keys": "^1.4.0",
2121
"husky": "^7.0.4",
22-
"jest": "^29.5.0",
22+
"jest": "^30.1.3",
2323
"lint-staged": "^15.2.7",
2424
"prettier": "^3.3.3",
2525
"pretty-quick": "^4.2.2",
26-
"ts-jest": "^29.2.4",
26+
"ts-jest": "^29.4.4",
2727
"ts-loader": "^9.5.1",
2828
"ts-node": "^10.9.2",
2929
"tsconfig-paths": "^4.2.0",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"resolve-from": "^5.0.0",
3535
"rimraf": "^5.0.10",
3636
"semver": "^7.6.3",
37-
"simple-git": "^3.25.0",
37+
"simple-git": "^3.28.0",
3838
"siwe": "^3.0.0",
3939
"terser-webpack-plugin": "^5.3.14",
4040
"ts-loader": "^9.5.1",

packages/cli/src/controller/init-controller.spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as fs from 'node:fs';
55
import os from 'node:os';
66
import path from 'node:path';
77
import {DEFAULT_TS_MANIFEST} from '@subql/common';
8-
import {simpleGit as git} from 'simple-git';
98
import {ENDPOINT_REG} from '../constants.js';
109
import {extractFromTs, findReplace, validateEthereumTsManifest} from '../utils/index.js';
1110
import {
@@ -18,12 +17,12 @@ import {
1817
validateEthereumProjectManifest,
1918
} from './init-controller.js';
2019

21-
jest.mock('simple-git', () => {
22-
const mGit = {
23-
clone: jest.fn(),
24-
};
25-
return jest.fn(() => mGit);
26-
});
20+
// jest.mock('simple-git', () => {
21+
// const mGit = {
22+
// clone: jest.fn(),
23+
// };
24+
// return jest.fn(() => mGit);
25+
// });
2726

2827
jest.setTimeout(30000);
2928

@@ -59,9 +58,6 @@ describe('Cli can create project (mocked)', () => {
5958
});
6059
it('throw error when git clone failed', async () => {
6160
const tempPath = await makeTempDir();
62-
(git().clone as jest.Mock).mockImplementationOnce((cb) => {
63-
cb(new Error());
64-
});
6561
await expect(cloneProjectGit(tempPath, projectSpec.name, 'invalid_url', 'invalid_branch')).rejects.toThrow(
6662
/Failed to clone starter template from git/
6763
);

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@nestjs/schematics": "^11.0.0",
3939
"@nestjs/testing": "^11.0.7",
4040
"@types/express": "^4.17.21",
41-
"@types/jest": "^27.5.2",
41+
"@types/jest": "^30.0.0",
4242
"@types/lodash": "^4.17.7",
4343
"dotenv": "^16.4.5",
4444
"graphql": "^15.8.0",

packages/query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@types/compression": "^1.7.5",
7575
"@types/express": "^4.17.21",
7676
"@types/express-pino-logger": "^4.0.5",
77-
"@types/jest": "^27.5.2",
77+
"@types/jest": "^30.0.0",
7878
"@types/lodash": "^4.17.7",
7979
"@types/ws": "^8",
8080
"@types/yargs": "^16.0.9",

0 commit comments

Comments
 (0)