Skip to content

Commit b4567a5

Browse files
Merge pull request #307 from iambumblehead/enable-swc-tests
update tests-FAIL-swc to newest swc call pattern. tests still fail
2 parents 40b049e + 6b0907c commit b4567a5

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

tests/tests-FAIL-swc/.swcrc

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2+
"$schema": "https://swc.rs/schema.json",
23
"test": ".*.ts$",
34
"jsc": {
45
"parser": {
56
"syntax": "typescript",
6-
"decorators": true
7+
"importMeta": true
78
},
8-
"transform": null
9+
"target": "es2022",
10+
"experimental": {
11+
"keepImportAssertions": true
12+
}
913
},
10-
"module": {
11-
"type": "es6"
12-
}
14+
"isModule": true
1315
}

tests/tests-FAIL-swc/esmock.node-swc.test.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import esmock from 'esmock'
66
// swc tests fail when encountering typescript syntax
77
// when the typescript sytax are removed, tests pass
88

9-
test('should mock ts when using node-ts', async () => {
10-
const main = await esmock('../local/main-ts.ts', {
9+
test('should mock js when using swc', async () => {
10+
const main = await esmock('../local/main.js', {
1111
path: {
1212
basename: () => 'hellow'
1313
}
@@ -16,14 +16,12 @@ test('should mock ts when using node-ts', async () => {
1616
assert.strictEqual(main.pathbasenamewrap(), 'hellow')
1717
})
1818

19-
test('should mock pg', async () => {
19+
test('should mock ts when using swc', async () => {
2020
const main = await esmock('../local/main-ts.ts', {
21-
'pg': {
22-
Pool: (config:any) => {
23-
return config || 'mocked pool'
24-
}
21+
path: {
22+
basename: () => 'hellow'
2523
}
2624
})
2725

28-
assert.strictEqual(main.pgpoolwrap(), 'mocked pool')
29-
})
26+
assert.strictEqual(main.pathbasenamewrap(), 'hellow')
27+
})

tests/tests-FAIL-swc/package.json

+8-12
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@
33
"description": "esmock unit tests, tsm with node native runner",
44
"repository": {
55
"type": "git",
6-
"url": "https://github.com/iambumblehead/esmock.git"
6+
"url": "git+https://github.com/iambumblehead/esmock.git"
77
},
88
"dependencies": {
9-
"@swc-node/register": "1.6.6",
109
"esmock": "file:..",
11-
"pg": "file:../node_modules/pg",
12-
"sinon": "file:../node_modules/sinon",
13-
"eslint": "file:../node_modules/eslint",
14-
"form-urlencoded": "file:../node_modules/form-urlencoded",
15-
"babelGeneratedDoubleDefault": "file:../local/babelGeneratedDoubleDefault"
10+
"@swc-node/register": "1.9.2"
1611
},
1712
"scripts": {
18-
"test:metaresolve": "node --experimental-import-meta-resolve --loader=@swc-node/register/esm --loader=esmock --test esmock.node-swc.test.ts",
19-
"test:nometaresolve": "node --loader=@swc-node/register/esm --loader=esmock --test esmock.node-swc.test.ts",
20-
"test": "npm run test:metaresolve && npm run test:nometaresolve",
21-
"test": "SWCRC=true node --loader=@swc-node/register/esm --loader=esmock --test esmock.node-swc.test.ts",
22-
"note": "⚠ https://github.com/swc-project/swc-node/issues/710"
13+
"isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"",
14+
"test:loader": "echo not-configured",
15+
"test:current": "node --import @swc-node/register/esm-register --test esmock.node-swc.test.ts",
16+
"test": "npm run isloaderavailable && npm run test:loader || npm run test:current",
17+
"note": "⚠ https://github.com/swc-project/swc-node/issues/710",
18+
"status": "swc error: SyntaxError: Unexpected identifier 'MockMap'"
2319
}
2420
}

tests/tests-FAIL-swc/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerOptions": {
44
"allowSyntheticDefaultImports": true,
55
"module": "ESNext",
6-
"moduleResolution": "node"
6+
"moduleResolution": "node",
7+
"lib": ["ES2015"]
78
}
89
}

0 commit comments

Comments
 (0)