Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: De-Typescriptify jest tests #328

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,866 changes: 2,724 additions & 5,142 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/npm-packages/ruby-3.2-wasm-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
],
"license": "MIT",
"devDependencies": {
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-json": "^6.0.1",
"rollup": "^4.6.1"
"rollup": "^4.6.1",
"rollup-plugin-polyfill-node": "^0.13.0"
},
"dependencies": {
"@ruby/wasm-wasi": "^2.0.0"
Expand Down
6 changes: 0 additions & 6 deletions packages/npm-packages/ruby-wasm-wasi/babel.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/npm-packages/ruby-wasm-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,12 @@
"build": "npm run build:rollup && npm run build:tsc && npm run build:static && ./tools/post-build.sh ./dist"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.23.5",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/jest": "^29.5.3",
"@types/node": "20.8.10",
"@wasmer/wasi": "^1.2.2",
"babel-jest": "^29.7.0",
"jest": "^29.6.2",
"prettier": "^3.0.0",
"rollup": "^4.6.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initRubyVM } from "./init";
const { initRubyVM } = require("./init");

describe("Ruby code evaluation", () => {
test("empty expression", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initRubyVM } from "./init";
const { initRubyVM } = require("./init");

describe("Async Ruby code evaluation", () => {
test("async eval over microtasks", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RbValue } from "../src/index";
import { initRubyVM } from "./init";
const { initRubyVM } = require("./init");

describe("GC integration", () => {
test("Wrapped Ruby object should live until wrapper will be released", async () => {
Expand All @@ -10,11 +9,11 @@ describe("GC integration", () => {
imports.call(:mark_js_object_live, JS::Object.wrap(Object.new))
end
`);
const livingObjects = new Set<RbValue>();
const livingObjects = new Set();
run.call(
"call",
vm.wrap({
mark_js_object_live: (object: RbValue) => {
mark_js_object_live: (object) => {
livingObjects.add(object);
},
}),
Expand All @@ -27,8 +26,8 @@ describe("GC integration", () => {
});

test("protect exported Ruby objects", async () => {
function dropRbValue(value: RbValue) {
(value as any).inner.drop();
function dropRbValue(value) {
value.inner.drop();
}
const vm = await initRubyVM();
const initialGCCount = Number(vm.eval("GC.count").toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs/promises";
import path from "path";
import { WASI } from "wasi";
import { RubyVM } from "../src/index";
const fs = require("fs/promises");
const path = require("path");
const { WASI } = require("wasi");
const { RubyVM } = require("../dist/cjs/index");

const rubyModule = (async () => {
let binaryPath;
Expand All @@ -19,7 +19,7 @@ const rubyModule = (async () => {
return await WebAssembly.compile(binary.buffer);
})();

export const initRubyVM = async (
const initRubyVM = async (
{ suppressStderr } = { suppressStderr: false },
) => {
let preopens = {};
Expand Down Expand Up @@ -47,3 +47,5 @@ export const initRubyVM = async (
vm.initialize();
return vm;
};

module.exports = { initRubyVM };
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from "fs/promises";
import path from "path";
import { WASI } from "wasi";
import { RubyVM } from "../dist/esm/index";
import { DefaultRubyVM } from "../dist/esm/node";
const fs = require("fs/promises");
const path = require("path");
const { WASI } = require("wasi");
const { RubyVM } = require("../dist/cjs/index");
const { DefaultRubyVM } = require("../dist/cjs/node");

const initRubyVM = async (rubyModule: WebAssembly.Module, args: string[]) => {
const initRubyVM = async (rubyModule, args) => {
const wasi = new WASI();
const vm = new RubyVM();
const imports = {
Expand Down Expand Up @@ -34,10 +34,10 @@ describe("Packaging validation", () => {
return;
}

const moduleCache = new Map<string, WebAssembly.Module>();
const loadWasmModule = async (file: string) => {
const moduleCache = new Map();
const loadWasmModule = async (file) => {
if (moduleCache.has(file)) {
return moduleCache.get(file)!;
return moduleCache.get(file);
}
const binary = await fs.readFile(
path.join(process.env.RUBY_NPM_PACKAGE_ROOT, `./dist/${file}`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initRubyVM } from "./init";
const { initRubyVM } = require("./init");

describe("RbValue#toJS", () => {
test.each([
Expand Down
4 changes: 0 additions & 4 deletions packages/npm-packages/ruby-wasm-wasi/test/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initRubyVM } from "./init";
const { initRubyVM } = require("./init");

describe("RubyVM", () => {
test("empty expression", async () => {
Expand Down Expand Up @@ -148,7 +148,7 @@ eval:11:in \`<main>'`);
setVM.call("call", vm.wrap(vm));

// HACK: We need to capture all promises to avoid unhandled promise rejection
const promises: Promise<any>[] = [];
const promises = [];
const _Promise = global.Promise;
const spy = jest.spyOn(global, "Promise").mockImplementation((future) => {
const promise = new _Promise(future);
Expand All @@ -158,7 +158,7 @@ eval:11:in \`<main>'`);

vm.evalAsync(code);

const rejections: Error[] = [];
const rejections = [];
for (const promise of promises) {
try {
await promise;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initRubyVM } from "./init";
const { initRubyVM } = require("./init");

describe("RubyVM#wrap", () => {
test("Wrap arbitrary JS object to RbValue", async () => {
Expand Down