Permalink
Browse files

Pretty-print TypeScript build errors

  • Loading branch information...
btkostner authored and novemberborn committed Jun 13, 2018
1 parent 199cc70 commit 5cce79addfdc772605b4ea9b324d9f4cece862ce
View
@@ -254,6 +254,11 @@ class MiniReporter {
}
writeErr(evt) {
if (evt.err.name === 'TSError' && evt.err.object && evt.err.object.diagnosticText) {
this.lineWriter.writeLine(colors.errorStack(trimOffNewlines(evt.err.object.diagnosticText)));
return;
}
if (evt.err.source) {
this.lineWriter.writeLine(colors.errorSource(`${evt.err.source.file}:${evt.err.source.line}`));
const excerpt = codeExcerpt(evt.err.source, {maxWidth: this.lineWriter.columns - 2});
View
@@ -198,6 +198,11 @@ class VerboseReporter {
}
writeErr(evt) {
if (evt.err.name === 'TSError' && evt.err.object && evt.err.object.diagnosticText) {
this.lineWriter.writeLine(colors.errorStack(trimOffNewlines(evt.err.object.diagnosticText)));
return;
}
if (evt.err.source) {
this.lineWriter.writeLine(colors.errorSource(`${evt.err.source.file}:${evt.err.source.line}`));
const excerpt = codeExcerpt(evt.err.source, {maxWidth: this.reportStream.columns - 2});
@@ -0,0 +1,2 @@
trigger.a.build.error();
lets.do.another();
@@ -0,0 +1 @@
{}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strict": true
}
}
View
@@ -63,6 +63,7 @@ exports.assert = (t, logFile, buffer, stripOptions) => {
exports.sanitizers = {
cwd: str => replaceString(str, process.cwd(), '~'),
lineEndings: str => replaceString(str, '\r\n', '\n'),
posix: str => replaceString(str, '\\', '/'),
slow: str => str.replace(/(slow.+?)\(\d+m?s\)/g, '$1 (000ms)'),
// At least in Appveyor with Node.js 6, IPC can overtake stdout/stderr. This
@@ -80,7 +81,7 @@ exports.sanitizers = {
const run = (type, reporter) => {
const projectDir = path.join(__dirname, '../fixture/report', type.toLowerCase());
const api = createApi({
const options = {
extensions: {
all: ['js'],
enhancementsOnly: [],
@@ -90,7 +91,7 @@ const run = (type, reporter) => {
failWithoutAssertions: false,
serial: type === 'failFast' || type === 'failFast2',
require: [],
cacheEnable: true,
cacheEnabled: true,
compileEnhancements: true,
match: [],
babelConfig: {testOptions: {}},
@@ -101,11 +102,21 @@ const run = (type, reporter) => {
updateSnapshots: false,
snapshotDir: false,
color: true
});
};
let pattern = '*.js';
if (type === 'typescript') {
options.extensions.all.push('ts');
options.extensions.enhancementsOnly.push('ts');
options.compileEnhancements = false;
options.require = ['ts-node/register'];
pattern = '*.ts';
}
const api = createApi(options);
api.on('run', plan => reporter.startRun(plan));
const files = globby.sync('*.js', {cwd: projectDir}).sort();
const files = globby.sync(pattern, {cwd: projectDir}).sort();
if (type !== 'watch') {
return api.run(files).then(() => {
reporter.endRun();
@@ -129,3 +140,4 @@ exports.failFast = reporter => run('failFast', reporter);
exports.failFast2 = reporter => run('failFast2', reporter);
exports.only = reporter => run('only', reporter);
exports.watch = reporter => run('watch', reporter);
exports.typescript = reporter => run('typescript', reporter);
View
@@ -8,14 +8,14 @@ const TTYStream = require('../helper/tty-stream');
const report = require('../helper/report');
const MiniReporter = require('../../lib/reporters/mini');
const run = type => t => {
const run = (type, sanitizers = []) => t => {
t.plan(1);
const logFile = path.join(__dirname, `mini.${type.toLowerCase()}.log`);
const tty = new TTYStream({
columns: 200,
sanitizers: [report.sanitizers.cwd, report.sanitizers.posix, report.sanitizers.unreliableProcessIO, report.sanitizers.version]
sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.posix, report.sanitizers.unreliableProcessIO, report.sanitizers.version]
});
const reporter = new MiniReporter({
spinner: {
@@ -41,3 +41,4 @@ test('mini reporter - failFast run', run('failFast'));
test('mini reporter - second failFast run', run('failFast2'));
test('mini reporter - only run', run('only'));
test('mini reporter - watch mode run', run('watch'));
test('mini reporter - typescript', run('typescript', [report.sanitizers.lineEndings]));
@@ -0,0 +1,14 @@
[?25l---tty-stream-chunk-separator
---tty-stream-chunk-separator
* ---tty-stream-chunk-separator
---tty-stream-chunk-separator
[?25h
1 uncaught exception
Uncaught exception in test/fixture/report/typescript/build-error.ts
build-error.ts(1,1): error TS2304: Cannot find name 'trigger'.
build-error.ts(2,1): error TS2304: Cannot find name 'lets'.
---tty-stream-chunk-separator
View
@@ -8,14 +8,14 @@ const TTYStream = require('../helper/tty-stream');
const report = require('../helper/report');
const TapReporter = require('../../lib/reporters/tap');
const run = type => t => {
const run = (type, sanitizers = []) => t => {
t.plan(1);
const logFile = path.join(__dirname, `tap.${type.toLowerCase()}.log`);
const tty = new TTYStream({
columns: 200,
sanitizers: [report.sanitizers.cwd, report.sanitizers.posix, report.sanitizers.unreliableProcessIO]
sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.posix, report.sanitizers.unreliableProcessIO]
});
const reporter = new TapReporter({
reportStream: tty,
@@ -8,14 +8,14 @@ const TTYStream = require('../helper/tty-stream');
const report = require('../helper/report');
const VerboseReporter = require('../../lib/reporters/verbose');
const run = type => t => {
const run = (type, sanitizers = []) => t => {
t.plan(1);
const logFile = path.join(__dirname, `verbose.${type.toLowerCase()}.log`);
const tty = new TTYStream({
columns: 200,
sanitizers: [report.sanitizers.cwd, report.sanitizers.posix, report.sanitizers.slow, report.sanitizers.unreliableProcessIO, report.sanitizers.version]
sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.posix, report.sanitizers.slow, report.sanitizers.unreliableProcessIO, report.sanitizers.version]
});
const reporter = new VerboseReporter({
reportStream: tty,
@@ -36,3 +36,4 @@ test('verbose reporter - failFast run', run('failFast'));
test('verbose reporter - second failFast run', run('failFast2'));
test('verbose reporter - only run', run('only'));
test('verbose reporter - watch mode run', run('watch'));
test('verbose reporter - typescript', run('typescript', [report.sanitizers.lineEndings]));
@@ -0,0 +1,14 @@
---tty-stream-chunk-separator
Uncaught exception in test/fixture/report/typescript/build-error.ts
build-error.ts(1,1): error TS2304: Cannot find name 'trigger'.
build-error.ts(2,1): error TS2304: Cannot find name 'lets'.
---tty-stream-chunk-separator
βœ– test/fixture/report/typescript/build-error.ts exited with a non-zero exit code: 1
---tty-stream-chunk-separator
1 uncaught exception
---tty-stream-chunk-separator

0 comments on commit 5cce79a

Please sign in to comment.