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

Make 'npm test' run on Windows #820

Merged
merged 1 commit into from Jun 28, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
@@ -1,7 +1,6 @@

TESTS = $(shell find test/test.*.js)

test:
@./test/run $(TESTS)
@./test/run.js

.PHONY: test
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"lint": "eslint index.js",
"test": "make test && npm run test-typings",
"test": "node test/run.js && npm run test-typings",
"test-typings": "node_modules/typescript/bin/tsc -p tsconfig.json"
},
"main": "index",
Expand Down
22 changes: 22 additions & 0 deletions test/run.js
@@ -0,0 +1,22 @@
#!/usr/bin/env node

const { spawnSync } = require('child_process')
const { readdirSync } = require('fs')
const { extname, join } = require('path')

process.env.NODE_ENV = 'test';

process.stdout.write('\n')
readdirSync(__dirname).forEach((file) => {
if (!file.startsWith('test.') || extname(file) !== '.js')
return;
process.stdout.write(`\x1b[90m ${file}\x1b[0m `);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does Windows support ANSI colors in terminal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since Win10 terminal control sequences are supported natively by the console. For previous Windows versions Node (libuv to be more precise) has special emulation layer that translates the codes to winapi calls.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok then! Thank you!

const result = spawnSync(process.argv0, [ join('test', file) ]);
if (result.status === 0) {
process.stdout.write('\x1b[36m✓\x1b[0m\n');
} else {
process.stdout.write('\x1b[31m✖\x1b[0m\n');
console.error(result.stderr.toString('utf8'));
process.exit(result.status);
}
})