-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test runner to two of the typescript tests to actually run them (…
…#3704) * Add jest for simple_struct.ts, this causes it to fail * fix the test, add another failing one * Fix the typescript_type test * do not use jest global injection * add TODO for the rest of the tests
- Loading branch information
1 parent
def9147
commit cfe3dc2
Showing
8 changed files
with
82 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest/presets/default-esm", | ||
testEnvironment: 'node', | ||
extensionsToTreatAsEsm: [".ts"], | ||
verbose: true, | ||
// TODO: match all test files | ||
testMatch: ['**/src/simple_struct.ts', '**/src/typescript_type.ts'], | ||
injectGlobals: false, | ||
globals: { | ||
'ts-jest': | ||
{ | ||
useESM: true, | ||
isolatedModules: true | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
{ | ||
"scripts": { | ||
"tsc": "tsc" | ||
"tsc": "tsc", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.config.cjs" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^3.3.3333" | ||
} | ||
"@types/jest": "^29.5.8", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import * as wbg from '../pkg/typescript_tests'; | ||
import * as wbg from "../pkg/typescript_tests"; | ||
import { expect, jest, test } from "@jest/globals"; | ||
|
||
const a = new wbg.A(); | ||
wbg.A.other(); | ||
a.foo(); | ||
a.free(); | ||
const b: boolean = a.ret_bool() | ||
a.take_bool(b); | ||
a.take_many(b, 1, 2); | ||
test("member function (void) -> void", () => { | ||
const a = new wbg.A(); | ||
wbg.A.other(); | ||
a.foo(); | ||
a.free(); | ||
expect(() => { | ||
a.ret_bool(); | ||
}).toThrow(/null pointer passed to rust/); | ||
}); | ||
|
||
test("function with parameters", () => { | ||
const a = new wbg.A(); | ||
const b: boolean = a.ret_bool(); | ||
expect(b).toStrictEqual(true); | ||
a.take_bool(b); | ||
a.take_many(b, 1, 2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import * as wbg from '../pkg/typescript_tests'; | ||
import * as wbg from "../pkg/typescript_tests"; | ||
import { expect, jest, test } from "@jest/globals"; | ||
|
||
const style: wbg.TextStyle = new wbg.TextStyle({ | ||
bold: true, | ||
italic: true, | ||
size: 42, | ||
test("constructor", () => { | ||
const style: wbg.TextStyle = new wbg.TextStyle({ | ||
bold: true, | ||
italic: false, | ||
size: 42, | ||
}); | ||
|
||
expect(style.bold).toStrictEqual(true); | ||
expect(style.italic).toStrictEqual(false); | ||
expect(style.size).toStrictEqual(42); | ||
}); | ||
|
||
const optional_style: wbg.TextStyle = wbg.TextStyle.optional_new(); | ||
test("optional parameter constructor", () => { | ||
const default_constructed: wbg.TextStyle = wbg.TextStyle.optional_new(); | ||
expect(default_constructed.bold).toStrictEqual(false); | ||
expect(default_constructed.italic).toStrictEqual(false); | ||
expect(default_constructed.size).toStrictEqual(0); | ||
|
||
const optional_style: wbg.TextStyle = wbg.TextStyle.optional_new({ | ||
italic: true, | ||
bold: false, | ||
size: 0, | ||
}); | ||
expect(optional_style.bold).toStrictEqual(false); | ||
expect(optional_style.italic).toStrictEqual(true); | ||
expect(optional_style.size).toStrictEqual(0); | ||
}); |