Skip to content

Commit

Permalink
properly test local ts integration (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and rauchg committed Jan 31, 2019
1 parent ac9a136 commit e121cd4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/typescript.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
module.exports = require("typescript");

const { Module } = require('module');
const m = new Module('', null);
m.paths = Module._nodeModulePaths(process.env.TYPESCRIPT_LOOKUP_PATH || (process.cwd() + '/'));
let typescript;
try {
typescript = m.require('typescript');
console.log("ncc: Using typescript@" + typescript.version + " (local user-provided)");
}
catch (e) {
typescript = require('typescript');
console.log("ncc: Using typescript@" + typescript.version + " (ncc built-in)");
}
module.exports = typescript;
11 changes: 11 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
}

it(`should execute "ncc run ${integrationTest}"`, async () => {
let expectedStdout;
try {
expectedStdout = fs.readFileSync(`${__dirname}/integration/${integrationTest}.stdout`).toString();
}
catch (e) {}
if (global.gc) global.gc();
const stdout = new StoreStream();
const stderr = new StoreStream();
Expand All @@ -90,6 +95,12 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
if (chunk.toString().startsWith('(node:')) return;
throw new Error(chunk.toString());
});
if (expectedStdout) {
let stdoutStr = '';
for (const chunk of stdout.data)
stdoutStr += chunk.toString();
expect(stdoutStr.startsWith(expectedStdout));
}
});
}

Expand Down
1 change: 1 addition & 0 deletions test/integration/node_modules/typescript/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/integration/node_modules/typescript/lib

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

2 changes: 2 additions & 0 deletions test/integration/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var p: boolean = false;
console.log(p);

0 comments on commit e121cd4

Please sign in to comment.