diff --git a/.vscode/launch.json b/.vscode/launch.json index d70e74e751..e1dd227cc5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,7 +15,7 @@ "program": "${workspaceRoot}/lib/nativescript-cli.js", // example commands - "args": [ "create", "cliapp"] + "args": [ "create", "cliapp", "--path", "${workspaceRoot}/scratch"] // "args": [ "test", "android", "--justlaunch"] // "args": [ "platform", "add", "android@1.3.0", "--path", "cliapp"] // "args": [ "platform", "remove", "android", "--path", "cliapp"] @@ -39,36 +39,6 @@ "sourceMaps": true }, - { - "type": "node", - "runtimeArgs": [ - "--harmony" - ], - "request": "launch", - "name": "Launch CLI (Node 4, Node 5)", - "program": "${workspaceRoot}/lib/nativescript-cli.js", - "cwd": "${workspaceRoot}", - "sourceMaps": true, - // define the arguments that you would like to pass to CLI, for example - // "args": [ "build", "android", "--justlaunch" ] - "args": [ - - ] - }, - - { - // in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...` - "type": "node", - "runtimeArgs": [ - "--harmony" - ], - "request": "launch", - "name": "Launch Tests (Node 4, Node 5)", - "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", - "cwd": "${workspaceRoot}", - "sourceMaps": true - }, - { "type": "node", "request": "attach", @@ -76,16 +46,6 @@ // In case you want to debug Analytics Broker process, add `--debug-brk=9897` (or --inspect-brk=9897) when spawning analytics-broker-process. "port": 9897, "sourceMaps": true - }, - - { - "type": "node", - "request": "attach", - "name": "Attach to Eqatec Process", - // In case you want to debug Eqatec Analytics process, add `--debug-brk=9855` (or --inspect-brk=9855) when spawning eqatec-analytics-process. - // NOTE: Ensure you set it only for one of the analytics processes. - "port": 9855, - "sourceMaps": true } ] diff --git a/bin/tns b/bin/tns index 79216cd7c7..fb5b323617 100755 --- a/bin/tns +++ b/bin/tns @@ -2,7 +2,6 @@ "use strict"; var path = require("path"), - node = require("../package.json").engines.node, pathToLib = path.join(__dirname, "..", "lib"), pathToCommon = path.join(pathToLib, "common"); @@ -10,27 +9,4 @@ require(path.join(pathToCommon, "verify-node-version")).verifyNodeVersion(); var pathToCliExecutable = path.join(pathToLib, "nativescript-cli.js"); -var nodeArgs = require(path.join(pathToCommon, "scripts", "node-args")).getNodeArgs(); - -if (nodeArgs.length) { - // We need custom args for Node process, so pass them here. - var childProcess = require("child_process"); - var args = process.argv; - - // Remove `node` and `nativescript` from the arguments. - args.shift(); - args.shift(); - - args.unshift(pathToCliExecutable); - - args = nodeArgs.concat(args); - - var nodeProcess = childProcess.spawn(process.execPath, args, { stdio: "inherit" }); - - nodeProcess.on("close", function (code) { - // We need this handler so if command fails, we'll exit with same exit code as CLI. - process.exit(code); - }); -} else { - require(pathToCliExecutable); -} +require(pathToCliExecutable); diff --git a/lib/common/scripts/node-args.js b/lib/common/scripts/node-args.js deleted file mode 100644 index 0a0371926f..0000000000 --- a/lib/common/scripts/node-args.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; - -const getNodeArgs = () => { - const nodeVersion = process.version; - const requiresHarmonyFlagRegex = /^v[45]\./; - const nodeArgs = []; - - if (requiresHarmonyFlagRegex.test(nodeVersion)) { - nodeArgs.push("--harmony"); - } - - return nodeArgs; -}; - -module.exports.getNodeArgs = getNodeArgs; \ No newline at end of file diff --git a/lib/common/test-scripts/istanbul.js b/lib/common/test-scripts/istanbul.js deleted file mode 100644 index 30f4acd21d..0000000000 --- a/lib/common/test-scripts/istanbul.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; - -const childProcess = require("child_process"); -const path = require("path"); -const pathToNodeModules = path.join(__dirname, "..", "node_modules"); -const pathToIstanbul = path.join(pathToNodeModules, "istanbul", "lib", "cli.js"); -const pathToMocha = path.join(pathToNodeModules, "mocha", "bin", "_mocha"); - -const istanbulArgs = [ pathToIstanbul, "cover", pathToMocha ]; - -const nodeArgs = require("../scripts/node-args").getNodeArgs(); - -const args = nodeArgs.concat(istanbulArgs); - -const nodeProcess = childProcess.spawn("node", args, { stdio: "inherit" }); -nodeProcess.on("close", (code) => { - // We need this handler so if any test fails, we'll exit with same exit code as istanbul. - process.exit(code); -}); \ No newline at end of file diff --git a/lib/common/test-scripts/mocha.js b/lib/common/test-scripts/mocha.js deleted file mode 100644 index 19b964e92a..0000000000 --- a/lib/common/test-scripts/mocha.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; - -const childProcess = require("child_process"); -const path = require("path"); -const pathToMocha = path.join(__dirname, "..", "node_modules", "mocha", "bin", "_mocha"); - -const nodeArgs = require("../scripts/node-args").getNodeArgs(); - -const args = nodeArgs.concat(pathToMocha); - -const nodeProcess = childProcess.spawn("node", args, { stdio: "inherit" }); -nodeProcess.on("close", (code) => { - // We need this handler so if any test fails, we'll exit with same exit code as mocha. - process.exit(code); -}); diff --git a/package.json b/package.json index 6deae80682..32393055df 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "main": "./lib/nativescript-cli-lib.js", "scripts": { "setup": "npm i --ignore-scripts && ./node_modules/.bin/grunt", - "test": "node test-scripts/istanbul.js", + "test": "istanbul cover ./node_modules/mocha/bin/_mocha", "postinstall": "node postinstall.js", "preuninstall": "node preuninstall.js", "prepack": "grunt prepare", "postpack": "grunt set_dev_ga_id", - "mocha": "node test-scripts/mocha.js", + "mocha": "mocha", "tsc": "tsc", "tslint": "tslint -p tsconfig.json --type-check", "test-watch": "node ./dev/tsc-to-mocha-watch.js", diff --git a/postinstall.js b/postinstall.js index 3c7693699d..5d3e0d3e25 100644 --- a/postinstall.js +++ b/postinstall.js @@ -4,8 +4,7 @@ var child_process = require("child_process"); var path = require("path"); var constants = require(path.join(__dirname, "lib", "constants")); var commandArgs = [path.join(__dirname, "bin", "tns"), constants.POST_INSTALL_COMMAND_NAME]; -var nodeArgs = require(path.join(__dirname, "lib", "common", "scripts", "node-args")).getNodeArgs(); var helpers = require(path.join(__dirname, "lib", "common", "helpers")); if (helpers.isInstallingNativeScriptGlobally()) { - child_process.spawn(process.argv[0], nodeArgs.concat(commandArgs), { stdio: "inherit" }); + child_process.spawn(process.argv[0], commandArgs, { stdio: "inherit" }); } diff --git a/preuninstall.js b/preuninstall.js index 09001e5095..252905118b 100644 --- a/preuninstall.js +++ b/preuninstall.js @@ -2,10 +2,8 @@ var child_process = require("child_process"); var commandArgs = ["bin/tns", "dev-preuninstall"]; -var path = require("path"); -var nodeArgs = require(path.join(__dirname, "lib", "common", "scripts", "node-args")).getNodeArgs(); -var child = child_process.exec("node " + nodeArgs.concat(commandArgs).join(" "), function (error) { +var child = child_process.exec("node " + commandArgs.join(" "), function (error) { if (error) { // Some npm versions (3.0, 3.5.1, 3.7.3) remove the NativeScript node_modules before the preuninstall script is executed and the script can't find them (the preuninstall script is like postinstall script). // The issue is described in the npm repository https://github.com/npm/npm/issues/8806 and it is not fixed in version 3.1.1 as commented in the conversation. diff --git a/test-scripts/istanbul.js b/test-scripts/istanbul.js deleted file mode 100644 index a1807e0985..0000000000 --- a/test-scripts/istanbul.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; - -const childProcess = require("child_process"); -const path = require("path"); -const pathToNodeModules = path.join(__dirname, "..", "node_modules"); -const pathToIstanbul = path.join(pathToNodeModules, "istanbul", "lib", "cli.js"); -const pathToMocha = path.join(pathToNodeModules, "mocha", "bin", "_mocha"); - -const istanbulArgs = [ pathToIstanbul, "cover", pathToMocha ]; - -const nodeArgs = require("../lib/common/scripts/node-args").getNodeArgs(); - -const args = nodeArgs.concat(istanbulArgs); - -const nodeProcess = childProcess.spawn("node", args, { stdio: "inherit" }); - -nodeProcess.on("close", (code) => { - // We need this handler so if any test fails, we'll exit with same exit code as istanbul. - process.exit(code); -}); \ No newline at end of file diff --git a/test-scripts/mocha.js b/test-scripts/mocha.js deleted file mode 100644 index a75c397f22..0000000000 --- a/test-scripts/mocha.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; - -const childProcess = require("child_process"); -const path = require("path"); -const pathToMocha = path.join(__dirname, "..", "node_modules", "mocha", "bin", "_mocha"); - -const nodeArgs = require("../lib/common/scripts/node-args").getNodeArgs(); - -const args = nodeArgs.concat(pathToMocha); - -const nodeProcess = childProcess.spawn("node", args, { stdio: "inherit" }); -nodeProcess.on("close", (code) => { - // We need this handler so if any test fails, we'll exit with same exit code as mocha. - process.exit(code); -}); diff --git a/test/nativescript-cli-lib.ts b/test/nativescript-cli-lib.ts index 9fa657a342..24cbf988f0 100644 --- a/test/nativescript-cli-lib.ts +++ b/test/nativescript-cli-lib.ts @@ -2,7 +2,6 @@ import { assert } from "chai"; import * as fs from "fs"; import * as path from "path"; import * as childProcess from "child_process"; -const nodeArgs = require(path.join(__dirname, "..", "lib", "common", "scripts", "node-args")).getNodeArgs(); describe("nativescript-cli-lib", () => { it("is main entry of the package", () => { @@ -67,7 +66,7 @@ describe("nativescript-cli-lib", () => { // For example $injector.register("errors", Errors) will add the errors module with its resolver (Errors) to $injector's cache. // Calling $injector.require("errors", ), that's executed in our bootstrap, will fail, as the module errors is already in the cache. // In order to workaround this problem, start new process and assert there. This way all files will not be required in it and $injector.require(...) will work correctly. - let testMethod = `"${process.execPath}" ${nodeArgs.join(" ")} -e "` + + let testMethod = `"${process.execPath}" -e "` + "var assert = require('chai').assert;" + `var result = require('${pathToEntryPoint}');` + `assert.ok(result.${moduleName});`;