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

fix: update power-doctest and remove vm2 #1680

Merged
merged 1 commit into from
Jul 15, 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
120 changes: 70 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
"@jxa/global-type": "^1.3.6",
"@jxa/run": "^1.3.6",
"@microsoft/eslint-formatter-sarif": "^3.0.0",
"@power-doctest/javascript": "^5.3.1",
"@power-doctest/markdown": "^5.3.2",
"@power-doctest/tester": "^5.3.2",
"@power-doctest/javascript": "^5.3.3",
"@power-doctest/markdown": "^5.3.3",
"@power-doctest/tester": "^5.3.3",
"@textlint-ja/textlint-rule-no-synonyms": "^1.3.0",
"@textlint-rule/textlint-rule-require-header-id": "^1.0.1",
"@textlint/regexp-string-matcher": "^2.0.2",
Expand Down Expand Up @@ -121,7 +121,6 @@
"unist-util-find-before": "^2.0.5",
"unist-util-parents": "^1.0.3",
"unist-util-select": "^3.0.4",
"vm2": "^3.9.18",
"wait-on": "^6.0.1",
"workbox-cli": "^3.6.3"
}
Expand Down
29 changes: 19 additions & 10 deletions test/lib/testing-code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NodeVM } from "vm2";
import vm from "vm";
import makeConsoleMock from "consolemock";

/**
* 次のコメントが実際に実行されないことをテストできるように変換する
*
Expand Down Expand Up @@ -75,14 +76,22 @@ export const toTestCode = (code) => {
* @param {string} filePath
*/
export const runTestCode = (code, filePath) => {
// Run Test Code
const vm = new NodeVM({
require: {
external: true,
context: {
console: !!process.env.ENABLE_CONSOLE ? console : makeConsoleMock()
}
}
const script = vm.Script(code, { filename: filePath });
const HostBuildIns = Object.freeze({
__proto__: null,
version: parseInt(process.versions.node.split(".")[0]),
require,
process,
console,
setTimeout,
setInterval,
setImmediate,
clearTimeout,
clearInterval,
clearImmediate,
});
script.runInNewContext({
...HostBuildIns,
console: !!process.env.ENABLE_CONSOLE ? console : makeConsoleMock()
});
vm.run(code, filePath);
};