Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
Convert tests to TypeScript without breaking dist output
Browse files Browse the repository at this point in the history
Co-Authored-By: Nathan Sobo <[email protected]>
  • Loading branch information
Antonio Scandurra and Nathan Sobo committed Oct 15, 2018
1 parent 0b3c9da commit 331121c
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Icon*
xray_wasm/dist
xray_browser/dist
memo_js/dist
memo_js/test/dist
5 changes: 4 additions & 1 deletion memo_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
"types": "dist/index.d.ts",
"scripts": {
"prepublishOnly": "script/build",
"test": "mocha --ui=tdd test",
"test": "webpack --env.test && mocha --ui=tdd --require=source-map-support/register test/dist/tests.js",
"tsc": "tsc",
"webpack": "webpack"
},
"license": "MIT",
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.4",
"mocha": "^5.2.0",
"source-map-support": "^0.5.9",
"ts-loader": "^5.2.0",
"typescript": "^3.0.3",
"webpack": "^4.20.2",
Expand Down
2 changes: 1 addition & 1 deletion memo_js/script/build
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ mkdir -p dist
CARGO_INCREMENTAL=0 RUSTFLAGS="-C debuginfo=0 -C opt-level=s -C lto -C panic=abort" cargo build --release --target wasm32-unknown-unknown
wasm-bindgen ../target/wasm32-unknown-unknown/release/memo_js.wasm --out-dir dist
yarn tsc
yarn webpack --mode=development
yarn webpack --mode=production
14 changes: 7 additions & 7 deletions memo_js/test/tests.js → memo_js/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const memo = require("../dist/index.node.js");
const assert = require("assert");
import * as memo from "../src/index";
import * as assert from 'assert';

suite("WorkTree", () => {
let WorkTree;
let WorkTree: typeof memo.WorkTree;

suiteSetup(async () => {
({ WorkTree } = await memo.init());
Expand All @@ -11,9 +11,9 @@ suite("WorkTree", () => {
test("basic API interaction", () => {
const rootFileId = WorkTree.getRootFileId();
const baseEntries = [
{ depth: 1, name: "a", type: "Directory" },
{ depth: 2, name: "b", type: "Directory" },
{ depth: 3, name: "c", type: "Text" }
{ depth: 1, name: "a", type: memo.FileType.Directory },
{ depth: 2, name: "b", type: memo.FileType.Directory },
{ depth: 3, name: "c", type: memo.FileType.Text }
];

const tree1 = new WorkTree(1);
Expand Down Expand Up @@ -122,6 +122,6 @@ suite("WorkTree", () => {
});
});

function point(row, column) {
function point(row: number, column: number): memo.Point {
return { row, column };
}
4 changes: 3 additions & 1 deletion memo_js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"include": ["src/**/*.ts"],
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "esnext",
"declarationMap": true,
"declaration": true,
"lib": ["es2015"]
"lib": ["es2015", "esnext"],
"types": ["mocha", "node"]
}
}
33 changes: 29 additions & 4 deletions memo_js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var path = require("path");

module.exports = {
entry: "./src/index.ts",
const baseConfig = {
target: "node",
module: {
rules: [
Expand All @@ -14,11 +13,37 @@ module.exports = {
},
resolve: {
extensions: [".ts", ".js", ".wasm"]
},
}
};

const libConfig = {
...baseConfig,
entry: "./src/index.ts",
mode: "production",
devtool: "source-map",
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.node.js",
library: "memo",
libraryTarget: "umd"
libraryTarget: "commonjs"
}
};

const testConfig = {
...baseConfig,
entry: "./test/tests.ts",
mode: "development",
devtool: "cheap-eval-source-map",
output: {
path: path.resolve(__dirname, "test", "dist"),
filename: "tests.js"
}
};

module.exports = env => {
if (env && env.test) {
return testConfig;
} else {
return libConfig;
}
};
Loading

0 comments on commit 331121c

Please sign in to comment.