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

tty.getWindowSize is not a function #250

Merged
merged 2 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 5 deletions src/subprocess/thread/worker.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { register: registerTypescriptHandler } = require('ts-node');

// monkeypatch Node.JS native TTY function
// otherwise mocha native base reporter throws exception
// inside a worker environment
require('tty').getWindowSize = () => 75;

registerTypescriptHandler();
require(`${__dirname}/worker.ts`);
6 changes: 5 additions & 1 deletion src/subprocess/thread/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { workerData } from 'worker_threads';
// monkeypatch Node.JS native TTY function
// otherwise mocha native base reporter throws exception
// inside a worker environment
require('tty').getWindowSize = () => 75;

import { workerData } from 'worker_threads';
import { runMocha } from '../runner';
import { WorkerData } from '../../main/thread/worker';

Expand Down
1 change: 1 addition & 0 deletions test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ test 'syntax errors' test/syntax-errors/index.js
test '--require option support' test/require-option/index.sh
test 'run programmatically (base API)' test/run-programmatically/callback/index.js
test 'run programmatically (reporter.done is called)' test/run-programmatically/reporter-done/index.js
test 'run programmatically (worker TTY)' test/run-programmatically/tty-worker/index.js
test '--no-exit option support' test/reporter-end-no-exit/index.js
test 'node native add-on' test/node-native-addon/index.sh
test 'skip-suite' test/skip-suite/index.sh
Expand Down
5 changes: 5 additions & 0 deletions test/run-programmatically/_spec/dummy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Dummy suite', () => {
it('should finish now', () => {
// pass
});
});
2 changes: 2 additions & 0 deletions test/run-programmatically/tty-worker/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Check that spec reporter can work in a non-TTY window
TODO: this test fails when you run index.js from the terminal but doesn't fail when it's executed from tests/index.sh
16 changes: 16 additions & 0 deletions test/run-programmatically/tty-worker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

'use strict';

const MochaParallelTests = require('../../../dist/main/mocha').default;
const mocha = new MochaParallelTests();

mocha
.reporter('spec')
.addFile(`${__dirname}/../_spec/dummy.js`)
.run();

process.on('unhandledRejection', (reason) => {
console.log(`Unhandled promise rejection: ${reason.stack}`);
process.exit(1);
});