Skip to content

Commit

Permalink
properly test local ts integration
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 29, 2019
1 parent e91832b commit 7a0116d
Show file tree
Hide file tree
Showing 5 changed files with 31 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;
13 changes: 13 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
// disabled pending https://github.com/zeit/ncc/issues/141
if (integrationTest.endsWith('loopback.js')) continue;

if (!integrationTest.endsWith('test.ts')) continue;

const { Writable } = require('stream');
class StoreStream extends Writable {
constructor (options) {
Expand All @@ -70,6 +72,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 +97,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 7a0116d

Please sign in to comment.