Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log typescript errors to console #1834

Merged
merged 12 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ class MiniReporter {
this.lineWriter.writeLine(evt.err.summary);
}

if (evt.err.name === 'TSError' && evt.err.object && evt.err.object.diagnosticText) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(evt.err.object.diagnosticText);
}

if (evt.err.stack) {
const stack = evt.err.stack;
if (stack.includes(os.EOL)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ class VerboseReporter {
this.lineWriter.writeLine(evt.err.summary);
}

if (evt.err.name === 'TSError' && evt.err.object && evt.err.object.diagnosticText) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(evt.err.object.diagnosticText);
}

if (evt.err.stack) {
const stack = evt.err.stack;
if (stack.includes('\n')) {
Expand Down
35 changes: 35 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"tap": "^12.0.1",
"temp-write": "^3.4.0",
"touch": "^3.1.0",
"ts-node": "^6.1.0",
"typescript": "^2.8.3",
"xo": "^0.21.1",
"zen-observable": "^0.8.8"
Expand Down
1 change: 1 addition & 0 deletions test/fixture/report/typescript/build-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this.is.a.build.error()
1 change: 1 addition & 0 deletions test/fixture/report/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 10 additions & 11 deletions test/fixture/source-map-initial.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
'use strict';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were made by the linter

"use strict";

var _sourceMapFixtures = require('source-map-fixtures');
var _sourceMapFixtures = require("source-map-fixtures");

var _ = require('../../');

var _2 = _interopRequireDefault(_);
var _ = _interopRequireDefault(require("../../"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const fixture = (0, _sourceMapFixtures.mapFile)('throws').require();

// The uncaught exception is passed to the corresponding cli test. The line
const fixture = (0, _sourceMapFixtures.mapFile)('throws').require(); // The uncaught exception is passed to the corresponding cli test. The line
// numbers from the 'throws' fixture (which uses a map file), as well as the
// line of the fixture.run() call, should match the source lines from this
// string.
(0, _2.default)('throw an uncaught exception', t => {
setImmediate(run);
t.pass();


(0, _.default)('throw an uncaught exception', t => {
setImmediate(run);
t.pass();
});

const run = () => fixture.run();
//# sourceMappingURL=./source-map-initial.js.map
// Generated using node test/fixtures/_generate-source-map-initial.js
2 changes: 1 addition & 1 deletion test/fixture/source-map-initial.js.map

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

19 changes: 14 additions & 5 deletions test/helper/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ exports.sanitizers = {

const run = (type, reporter) => {
const projectDir = path.join(__dirname, '../fixture/report', type.toLowerCase());
const extension = (type === 'typescript') ? 'ts' : 'js';

const api = createApi({
const options = {
extensions: {
all: ['js'],
all: [extension],
enhancementsOnly: [],
full: ['js']
full: [extension]
},
failFast: type === 'failFast' || type === 'failFast2',
failWithoutAssertions: false,
Expand All @@ -99,11 +100,18 @@ const run = (type, reporter) => {
updateSnapshots: false,
snapshotDir: false,
color: true
});
};

if (type === 'typescript') {
options.compileEnhancements = false;
options.require = ['ts-node/register'];
}

const api = createApi(options);

api.on('run', plan => reporter.startRun(plan));

const files = globby.sync('*.js', {cwd: projectDir}).sort();
const files = globby.sync('*.' + extension, {cwd: projectDir}).sort();
if (type !== 'watch') {
return api.run(files).then(() => {
reporter.endRun();
Expand All @@ -127,3 +135,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);
1 change: 1 addition & 0 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
24 changes: 24 additions & 0 deletions test/reporters/mini.typescript.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[?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

~/node_modules/ts-node/src/index.ts:250

TSError: ⨯ Unable to compile TypeScript:

build-error.ts(3,1): error TS2532: Object is possibly 'undefined'.


createTSError (~/node_modules/ts-node/src/index.ts:250:12)
getOutput (~/node_modules/ts-node/src/index.ts:358:40)
Object.compile (~/node_modules/ts-node/src/index.ts:545:11)
Module.m._compile (~/node_modules/ts-node/src/index.ts:430:43)
Object.require.extensions.(anonymous function) [as .ts] (~/node_modules/ts-node/src/index.ts:433:12)

---tty-stream-chunk-separator
1 change: 1 addition & 0 deletions test/reporters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ test('verbose reporter - regular run', run('regular'));
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 - typescript', run('typescript'));
27 changes: 27 additions & 0 deletions test/reporters/tap.typescript.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
TAP version 13
---tty-stream-chunk-separator
# TSError: ⨯ Unable to compile TypeScript:
not ok 1 - TSError: ⨯ Unable to compile TypeScript:
---
diagnosticText: |
build-error.ts(3,1): error TS2532: Object is possibly 'undefined'.
diagnosticCodes: []
name: TSError
message: |
⨯ Unable to compile TypeScript:
build-error.ts(3,1): error TS2532: Object is possibly 'undefined'.
at: >-
createTSError
(~/node_modules/ts-node/src/index.ts:250:12)
...
---tty-stream-chunk-separator
# test/fixture/report/typescript/build-error.ts exited with a non-zero exit code: 1
not ok 2 - test/fixture/report/typescript/build-error.ts exited with a non-zero exit code: 1
---tty-stream-chunk-separator

1..0
# tests 0
# pass 0
# fail 2

---tty-stream-chunk-separator
1 change: 1 addition & 0 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
24 changes: 24 additions & 0 deletions test/reporters/verbose.typescript.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

---tty-stream-chunk-separator
Uncaught exception in test/fixture/report/typescript/build-error.ts

~/node_modules/ts-node/src/index.ts:250

TSError: ⨯ Unable to compile TypeScript:

build-error.ts(3,1): error TS2532: Object is possibly 'undefined'.


createTSError (~/node_modules/ts-node/src/index.ts:250:12)
getOutput (~/node_modules/ts-node/src/index.ts:358:40)
Object.compile (~/node_modules/ts-node/src/index.ts:545:11)
Module.m._compile (~/node_modules/ts-node/src/index.ts:430:43)
Object.require.extensions.(anonymous function) [as .ts] (~/node_modules/ts-node/src/index.ts:433:12)

---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