Skip to content

Commit

Permalink
fix: update power-doctest and remove vm2 (#1680)
Browse files Browse the repository at this point in the history
Signed-off-by: azu <[email protected]>
  • Loading branch information
azu authored Jul 15, 2023
1 parent f98cf43 commit 0fc8ee0
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 64 deletions.
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);
};

0 comments on commit 0fc8ee0

Please sign in to comment.