Skip to content

Commit fca1eb4

Browse files
test: De-Typescriptify jest tests
Jest with TS brings in a lot of dependencies even though types are not so much helpful in tests. This commit removes TS from jest test suites and makes them plain CommonJS.
1 parent 06a03b0 commit fca1eb4

File tree

13 files changed

+2755
-5184
lines changed

13 files changed

+2755
-5184
lines changed

package-lock.json

Lines changed: 2724 additions & 5142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/npm-packages/ruby-3.2-wasm-wasi/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
],
4646
"license": "MIT",
4747
"devDependencies": {
48+
"@rollup/plugin-inject": "^5.0.5",
4849
"@rollup/plugin-json": "^6.0.1",
49-
"rollup": "^4.6.1"
50+
"rollup": "^4.6.1",
51+
"rollup-plugin-polyfill-node": "^0.13.0"
5052
},
5153
"dependencies": {
5254
"@ruby/wasm-wasi": "^2.0.0"

packages/npm-packages/ruby-wasm-wasi/babel.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/npm-packages/ruby-wasm-wasi/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,12 @@
5555
"build": "npm run build:rollup && npm run build:tsc && npm run build:static && ./tools/post-build.sh ./dist"
5656
},
5757
"devDependencies": {
58-
"@babel/core": "^7.19.3",
59-
"@babel/preset-env": "^7.23.5",
60-
"@babel/preset-typescript": "^7.18.6",
6158
"@rollup/plugin-inject": "^5.0.5",
6259
"@rollup/plugin-node-resolve": "^15.1.0",
6360
"@rollup/plugin-typescript": "^11.1.2",
6461
"@types/jest": "^29.5.3",
6562
"@types/node": "20.8.10",
6663
"@wasmer/wasi": "^1.2.2",
67-
"babel-jest": "^29.7.0",
6864
"jest": "^29.6.2",
6965
"prettier": "^3.0.0",
7066
"rollup": "^4.6.1",

packages/npm-packages/ruby-wasm-wasi/test/eval.test.ts renamed to packages/npm-packages/ruby-wasm-wasi/test/eval.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initRubyVM } from "./init";
1+
const { initRubyVM } = require("./init");
22

33
describe("Ruby code evaluation", () => {
44
test("empty expression", async () => {

packages/npm-packages/ruby-wasm-wasi/test/eval_async.test.ts renamed to packages/npm-packages/ruby-wasm-wasi/test/eval_async.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initRubyVM } from "./init";
1+
const { initRubyVM } = require("./init");
22

33
describe("Async Ruby code evaluation", () => {
44
test("async eval over microtasks", async () => {

packages/npm-packages/ruby-wasm-wasi/test/gc.test.ts renamed to packages/npm-packages/ruby-wasm-wasi/test/gc.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RbValue } from "../src/index";
2-
import { initRubyVM } from "./init";
1+
const { initRubyVM } = require("./init");
32

43
describe("GC integration", () => {
54
test("Wrapped Ruby object should live until wrapper will be released", async () => {
@@ -10,11 +9,11 @@ describe("GC integration", () => {
109
imports.call(:mark_js_object_live, JS::Object.wrap(Object.new))
1110
end
1211
`);
13-
const livingObjects = new Set<RbValue>();
12+
const livingObjects = new Set();
1413
run.call(
1514
"call",
1615
vm.wrap({
17-
mark_js_object_live: (object: RbValue) => {
16+
mark_js_object_live: (object) => {
1817
livingObjects.add(object);
1918
},
2019
}),
@@ -27,8 +26,8 @@ describe("GC integration", () => {
2726
});
2827

2928
test("protect exported Ruby objects", async () => {
30-
function dropRbValue(value: RbValue) {
31-
(value as any).inner.drop();
29+
function dropRbValue(value) {
30+
value.inner.drop();
3231
}
3332
const vm = await initRubyVM();
3433
const initialGCCount = Number(vm.eval("GC.count").toString());

packages/npm-packages/ruby-wasm-wasi/test/init.ts renamed to packages/npm-packages/ruby-wasm-wasi/test/init.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import fs from "fs/promises";
2-
import path from "path";
3-
import { WASI } from "wasi";
4-
import { RubyVM } from "../src/index";
1+
const fs = require("fs/promises");
2+
const path = require("path");
3+
const { WASI } = require("wasi");
4+
const { RubyVM } = require("../dist/cjs/index");
55

66
const rubyModule = (async () => {
77
let binaryPath;
@@ -19,7 +19,7 @@ const rubyModule = (async () => {
1919
return await WebAssembly.compile(binary.buffer);
2020
})();
2121

22-
export const initRubyVM = async (
22+
const initRubyVM = async (
2323
{ suppressStderr } = { suppressStderr: false },
2424
) => {
2525
let preopens = {};
@@ -47,3 +47,5 @@ export const initRubyVM = async (
4747
vm.initialize();
4848
return vm;
4949
};
50+
51+
module.exports = { initRubyVM };

packages/npm-packages/ruby-wasm-wasi/test/package.test.ts renamed to packages/npm-packages/ruby-wasm-wasi/test/package.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import fs from "fs/promises";
2-
import path from "path";
3-
import { WASI } from "wasi";
4-
import { RubyVM } from "../dist/esm/index";
5-
import { DefaultRubyVM } from "../dist/esm/node";
1+
const fs = require("fs/promises");
2+
const path = require("path");
3+
const { WASI } = require("wasi");
4+
const { RubyVM } = require("../dist/cjs/index");
5+
const { DefaultRubyVM } = require("../dist/cjs/node");
66

7-
const initRubyVM = async (rubyModule: WebAssembly.Module, args: string[]) => {
7+
const initRubyVM = async (rubyModule, args) => {
88
const wasi = new WASI();
99
const vm = new RubyVM();
1010
const imports = {
@@ -34,10 +34,10 @@ describe("Packaging validation", () => {
3434
return;
3535
}
3636

37-
const moduleCache = new Map<string, WebAssembly.Module>();
38-
const loadWasmModule = async (file: string) => {
37+
const moduleCache = new Map();
38+
const loadWasmModule = async (file) => {
3939
if (moduleCache.has(file)) {
40-
return moduleCache.get(file)!;
40+
return moduleCache.get(file);
4141
}
4242
const binary = await fs.readFile(
4343
path.join(process.env.RUBY_NPM_PACKAGE_ROOT, `./dist/${file}`),

packages/npm-packages/ruby-wasm-wasi/test/to_js.test.ts renamed to packages/npm-packages/ruby-wasm-wasi/test/to_js.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initRubyVM } from "./init";
1+
const { initRubyVM } = require("./init");
22

33
describe("RbValue#toJS", () => {
44
test.each([

0 commit comments

Comments
 (0)