aboutsummaryrefslogtreecommitdiff
path: root/test/sequential/test-cli-syntax-bad.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2018-12-09 09:44:44 -0800
committerRich Trott <rtrott@gmail.com>2018-12-12 21:06:06 -0800
commita3801e96835821b71dd97b3f8513c56814bcf8fa (patch)
tree238d893477aebf3b01ee376f48f92efd141c1d5a /test/sequential/test-cli-syntax-bad.js
parentc61327d37673ab2ea454d14c36329b113aaca32a (diff)
downloadandroid-node-v8-a3801e96835821b71dd97b3f8513c56814bcf8fa.tar.gz
android-node-v8-a3801e96835821b71dd97b3f8513c56814bcf8fa.tar.bz2
android-node-v8-a3801e96835821b71dd97b3f8513c56814bcf8fa.zip
test: split test-cli-syntax into multiple tests
Split test-cli-syntax into multiple files to improve reliability and/or isolate unreliable test cases. Move test cases back to parallel as appropriate. PR-URL: https://github.com/nodejs/node/pull/24922 Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'test/sequential/test-cli-syntax-bad.js')
-rw-r--r--test/sequential/test-cli-syntax-bad.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/sequential/test-cli-syntax-bad.js b/test/sequential/test-cli-syntax-bad.js
new file mode 100644
index 0000000000..e1c7f3bec5
--- /dev/null
+++ b/test/sequential/test-cli-syntax-bad.js
@@ -0,0 +1,47 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const { exec } = require('child_process');
+const fixtures = require('../common/fixtures');
+
+const node = process.execPath;
+
+// test both sets of arguments that check syntax
+const syntaxArgs = [
+ ['-c'],
+ ['--check']
+];
+
+// Match on the name of the `Error` but not the message as it is different
+// depending on the JavaScript engine.
+const syntaxErrorRE = /^SyntaxError: \b/m;
+
+// test bad syntax with and without shebang
+[
+ 'syntax/bad_syntax.js',
+ 'syntax/bad_syntax',
+ 'syntax/bad_syntax_shebang.js',
+ 'syntax/bad_syntax_shebang'
+].forEach(function(file) {
+ file = fixtures.path(file);
+
+ // loop each possible option, `-c` or `--check`
+ syntaxArgs.forEach(function(args) {
+ const _args = args.concat(file);
+ const cmd = [node, ..._args].join(' ');
+ exec(cmd, common.mustCall((err, stdout, stderr) => {
+ assert.strictEqual(err instanceof Error, true);
+ assert.strictEqual(err.code, 1);
+
+ // no stdout should be produced
+ assert.strictEqual(stdout, '');
+
+ // stderr should have a syntax error message
+ assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`);
+
+ // stderr should include the filename
+ assert(stderr.startsWith(file), `${stderr} starts with ${file}`);
+ }));
+ });
+});