mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-24 07:02:26 +01:00
Add tests for NetscriptJS
This commit is contained in:
parent
ebd5aacb89
commit
3fe254494e
@ -855,5 +855,5 @@
|
|||||||
<div class="loaderlabel">Loading Bitburner...</div>
|
<div class="loaderlabel">Loading Bitburner...</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script src="dist/bundle.js"></script>
|
<script src="dist/engine.bundle.js"></script>
|
||||||
</html>
|
</html>
|
||||||
|
2525
package-lock.json
generated
2525
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -43,6 +43,8 @@
|
|||||||
"beautify-lint": "^1.0.3",
|
"beautify-lint": "^1.0.3",
|
||||||
"benchmark": "^2.1.1",
|
"benchmark": "^2.1.1",
|
||||||
"bundle-loader": "~0.5.0",
|
"bundle-loader": "~0.5.0",
|
||||||
|
"chai": "^4.1.2",
|
||||||
|
"chai-as-promised": "^7.1.1",
|
||||||
"codacy-coverage": "^2.0.1",
|
"codacy-coverage": "^2.0.1",
|
||||||
"codecov.io": "^0.1.2",
|
"codecov.io": "^0.1.2",
|
||||||
"coffee-loader": "~0.7.1",
|
"coffee-loader": "~0.7.1",
|
||||||
@ -80,6 +82,7 @@
|
|||||||
"webpack": "^4.1.1",
|
"webpack": "^4.1.1",
|
||||||
"webpack-cli": "^2.0.12",
|
"webpack-cli": "^2.0.12",
|
||||||
"webpack-dev-middleware": "^1.9.0",
|
"webpack-dev-middleware": "^1.9.0",
|
||||||
|
"webpack-dev-server": "^3.1.4",
|
||||||
"worker-loader": "^0.8.0"
|
"worker-loader": "^0.8.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@ -108,6 +111,7 @@
|
|||||||
"nsp": "nsp check --output summary",
|
"nsp": "nsp check --output summary",
|
||||||
"pretest": "npm run lint-files",
|
"pretest": "npm run lint-files",
|
||||||
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish",
|
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish",
|
||||||
|
"start:dev": "webpack-dev-server",
|
||||||
"test": "mocha test/*.test.js --max-old-space-size=4096 --harmony --check-leaks",
|
"test": "mocha test/*.test.js --max-old-space-size=4096 --harmony --check-leaks",
|
||||||
"travis:benchmark": "npm run benchmark",
|
"travis:benchmark": "npm run benchmark",
|
||||||
"travis:lint": "npm run lint-files && npm run nsp",
|
"travis:lint": "npm run lint-files && npm run nsp",
|
||||||
|
49
tests/NetscriptJSTest.js
Normal file
49
tests/NetscriptJSTest.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import {executeJSScript} from "../src/NetscriptJSEvaluator.js";
|
||||||
|
|
||||||
|
const chai = require("chai");
|
||||||
|
const chaiAsPromised = require("chai-as-promised");
|
||||||
|
chai.should();
|
||||||
|
chai.use(chaiAsPromised);
|
||||||
|
|
||||||
|
console.info('asdf');
|
||||||
|
|
||||||
|
describe('NSJS ScriptStore', function() {
|
||||||
|
it('should run an imported function', async function() {
|
||||||
|
const s = { filename: "", code: "export function main() { return 2; }" };
|
||||||
|
chai.expect(await executeJSScript(s)).to.equal(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle recursive imports', async function() {
|
||||||
|
const s1 = { filename: "s1.js", code: "export function iAmRecursiveImport(x) { return x + 2; }" };
|
||||||
|
const s2 = { filename: "", code: `
|
||||||
|
import {iAmRecursiveImport} from \"s1.js\";
|
||||||
|
export function main() { return iAmRecursiveImport(3);
|
||||||
|
}`};
|
||||||
|
chai.expect(await executeJSScript(s2, [s1, s2])).to.equal(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it (`should correctly reference the passed global env`, async function() {
|
||||||
|
var [x, y] = [0, 0];
|
||||||
|
var env = {
|
||||||
|
updateX: function(value) { x = value; },
|
||||||
|
updateY: function(value) { y = value; },
|
||||||
|
};
|
||||||
|
const s1 = {filename: "s1.js", code: "export function importedFn(x) { updateX(x); }"};
|
||||||
|
const s2 = {filename: "s2.js", code: `
|
||||||
|
import {importedFn} from "s1.js";
|
||||||
|
export function main() { updateY(7); importedFn(3); }
|
||||||
|
`}
|
||||||
|
await executeJSScript(s2, [s1, s2], env);
|
||||||
|
chai.expect(y).to.equal(7);
|
||||||
|
chai.expect(x).to.equal(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it (`should throw on circular dep`, async function() {
|
||||||
|
const s1 = {filename: "s1.js", code: "import \"s2.js\""};
|
||||||
|
const s2 = {filename: "s2.js", code: `
|
||||||
|
import * as s1 from "s1.js";
|
||||||
|
export function main() {}
|
||||||
|
`}
|
||||||
|
executeJSScript(s2, [s1, s2]).should.eventually.throw();
|
||||||
|
});
|
||||||
|
});
|
20
tests/index.html
Normal file
20
tests/index.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<html>
|
||||||
|
<!-- From https://medium.com/dailyjs/running-mocha-tests-as-native-es6-modules-in-a-browser-882373f2ecb0 -->
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Mocha Tests</title>
|
||||||
|
<link href="https://unpkg.com/mocha@4.0.1/mocha.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="mocha"></div>
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/mocha@4.0.1/mocha.js"></script>
|
||||||
|
|
||||||
|
<script>mocha.setup('bdd')</script>
|
||||||
|
<script type="module" src="../tests.bundle.js"></script>
|
||||||
|
<script type="module">
|
||||||
|
mocha.checkLeaks();
|
||||||
|
mocha.run();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
tests/index.js
Normal file
3
tests/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
//require("babel-core/register");
|
||||||
|
//require("babel-polyfill");
|
||||||
|
module.exports = require("./NetscriptJSTest.js");
|
@ -15,11 +15,14 @@ module.exports = {
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
target: "web",
|
target: "web",
|
||||||
entry: "./src/engine.js",
|
entry: {
|
||||||
|
engine: "./src/engine.js",
|
||||||
|
tests: "./tests/index.js",
|
||||||
|
},
|
||||||
devtool: "nosources-source-map",
|
devtool: "nosources-source-map",
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, "dist"),
|
path: path.resolve(__dirname, "dist"),
|
||||||
filename: "bundle.js",
|
filename: "[name].bundle.js",
|
||||||
devtoolModuleFilenameTemplate: "[id]"
|
devtoolModuleFilenameTemplate: "[id]"
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
|
Loading…
Reference in New Issue
Block a user