Files
swc/packages/core/e2e/plugins/plugins.compat.test.js
bbda1f4f59 test: Use rstest as the test framework (#11417)
Use Rstest instead of Jest when test `packages/core` and `wasm binding`.

https://rstest.rs/


```bash
$ cd packages/core
$ hyperfine  'yarn run test' 'yarn run test:rstest'             

Benchmark 1: yarn run test
  Time (mean ± σ):      2.346 s ±  0.187 s    [User: 5.283 s, System: 3.705 s]
  Range (min … max):    1.983 s …  2.564 s    10 runs

Benchmark 2: yarn run test:rstest
  Time (mean ± σ):      1.740 s ±  0.372 s    [User: 4.115 s, System: 1.388 s]
  Range (min … max):    1.440 s …  2.668 s    10 runs

Summary
  yarn run test:rstest ran
    1.35 ± 0.31 times faster than yarn run test
```

---------

Co-authored-by: Copilot <[email protected]>
2026-01-07 23:23:25 +09:00

147 lines
4.2 KiB
JavaScript

/// <reference types="@rstest/core/globals" />
const { getPkgRoot } = require("../utils");
const path = require("path");
const { readFileSync } = require("fs");
const { platform, arch } = process;
const isMusl = () =>
(() => {
function isMusl() {
if (
!process.report ||
typeof process.report.getReport !== "function"
) {
try {
return readFileSync("/usr/bin/ldd", "utf8").includes(
"musl"
);
} catch (e) {
return true;
}
} else {
const { glibcVersionRuntime } =
process.report.getReport().header;
return !glibcVersionRuntime;
}
}
return isMusl();
})();
const platformPackagesMap = {
win32: {
x64: "swc.win32-x64-msvc.node",
ia32: "swc.win32-ia32-msvc.node",
arm64: "swc.win32-arm64-msvc.node",
},
darwin: {
x64: "swc.darwin-x64.node",
arm64: "swc.darwin-arm64.node",
},
linux: {
x64: `swc.linux-x64-${isMusl() ? "musl" : "gnu"}.node`,
arm64: `swc.linux-arm64-${isMusl() ? "musl" : "gnu"}.node`,
arm: "swc.linux-arm64-gnu.node",
},
};
const inferBinaryName = () => {
const packageName = platformPackagesMap[platform][arch];
if (!packageName) {
throw new Error(
`Unsupported platform: binary for '${platform} ${arch}' is not available`
);
}
return path.join(
path.dirname(require.resolve(packageName)),
platform === "win32" ? "swc.exe" : "swc"
);
};
describe.skip("Published plugins", () => {
const packageName = platformPackagesMap[platform][arch];
if (!!packageName) {
it("should compile without seg fault", () => {
const { transformSync } = require(path.resolve(
getPkgRoot(),
packageName
));
console.log(`Package name: ${packageName}`);
const options = {
jsc: {
target: "es5",
parser: {
syntax: "typescript",
},
experimental: {
plugins: [
["@swc/plugin-jest", {}],
// Disabled because this plugin is broken
// ["swc-plugin-coverage-instrument", {}],
],
},
},
};
console.log("Before transformSync");
const { code } = transformSync(
'console.log("hello world")',
false,
Buffer.from(JSON.stringify(options))
);
console.log("After transformSync");
expect(code).toMatchInlineSnapshot(`
"console.log("hello world");
"
`);
});
it("should compile without seg fault (async)", async () => {
const { transform } = require(path.resolve(
getPkgRoot(),
packageName
));
console.log(`Package name: ${packageName}`);
const options = {
jsc: {
target: "es5",
parser: {
syntax: "typescript",
},
experimental: {
plugins: [
["@swc/plugin-jest", {}],
// Disabled because this plugin is broken
// ["swc-plugin-coverage-instrument", {}],
],
},
},
};
console.log("Before transform");
const { code } = await transform(
'console.log("hello world")',
false,
Buffer.from(JSON.stringify(options))
);
console.log("After transform");
expect(code).toMatchInlineSnapshot(`
"console.log("hello world");
"
`);
});
}
});