From 4f5925e7afaaba5d2f8098486d98491127fc4a85 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Fri, 3 Jun 2016 16:39:09 +0100 Subject: [PATCH 1/8] Add support for Tape JS test framework. --- Nodejs/Product/Nodejs/Nodejs.csproj | 3 + .../Nodejs/TestFrameworks/Tape/tape.js | 75 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js diff --git a/Nodejs/Product/Nodejs/Nodejs.csproj b/Nodejs/Product/Nodejs/Nodejs.csproj index 88e49ab4f..c54d37f9b 100644 --- a/Nodejs/Product/Nodejs/Nodejs.csproj +++ b/Nodejs/Product/Nodejs/Nodejs.csproj @@ -1311,6 +1311,9 @@ + + PreserveNewest + true PreserveNewest diff --git a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js new file mode 100644 index 000000000..8754f1b52 --- /dev/null +++ b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js @@ -0,0 +1,75 @@ +var fs = require('fs'); +var path = require('path'); + +function find_tests(testFileList, discoverResultFile, projectFolder) { + var test = findTape(projectFolder); + if (test === null) { + console.error("NTVS_ERROR:", "Couldn't find 'tape' module relative to", projectFolder); + return; + } + + var harness = test.getHarness({ exit: false }); + var tests = harness["_tests"]; + + var count = 0; + var testList = []; + testFileList.split(';').forEach(function (testFile) { + + var testCases; + process.chdir(path.dirname(testFile)); + try { + testCases = require(testFile); + } catch (ex) { + console.error("NTVS_ERROR:", ex, "in", testFile); + return; + } + + for (; count < tests.length; count++) { + var t = tests[count]; + t._skip = true; // Don't run tests. + testList.push({ + test: t.name, + suite: '', + file: testFile, + line: 1, + column: 1 + }); + } + }); + + var fd = fs.openSync(discoverResultFile, 'w'); + fs.writeSync(fd, JSON.stringify(testList)); + fs.closeSync(fd); +}; +module.exports.find_tests = find_tests; + +function run_tests(testName, testFile, workingFolder, projectFolder) { + var testCases; + process.chdir(path.dirname(testFile)); + try { + testCases = require(testFile); + } catch (ex) { + console.error("NTVS_ERROR:", ex, "in", testFile); + return; + } + + try { + var test = findTape(projectFolder); + if (test === null) { + console.error("NTVS_ERROR:", "Couldn't find 'tape' module relative to", projectFolder); + return; + } + + var harness = test.getHarness(); + harness.only(testName); + } catch (ex) { + console.error("NTVS_ERROR:", ex); + return; + } +} +module.exports.run_tests = run_tests; + +function findTape(projectFolder) { + var tapePath = path.join(projectFolder, 'node_modules', 'tape'); + return require(tapePath); +} From b7c37e93b242115e35d576ae027f93599fd915b2 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Tue, 7 Jun 2016 00:57:10 +0100 Subject: [PATCH 2/8] JavaScript test runners can now use 0-based line/column numbers. --- Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js index 8754f1b52..11ab1804d 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js @@ -31,8 +31,8 @@ function find_tests(testFileList, discoverResultFile, projectFolder) { test: t.name, suite: '', file: testFile, - line: 1, - column: 1 + line: 0, + column: 0 }); } }); From 1bd96d22267490825cd1f7075b01c743c98ff40c Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Wed, 8 Jun 2016 12:47:14 +0100 Subject: [PATCH 3/8] Added 'TestFrameworks\Tape' folder to Wix installer file. Is this enough to include contents of directory (i.e. 'tape.js')? --- Nodejs/Setup/NodejsTools/NodejsTools.wxs | 1 + 1 file changed, 1 insertion(+) diff --git a/Nodejs/Setup/NodejsTools/NodejsTools.wxs b/Nodejs/Setup/NodejsTools/NodejsTools.wxs index 5eec307c1..f985861b6 100644 --- a/Nodejs/Setup/NodejsTools/NodejsTools.wxs +++ b/Nodejs/Setup/NodejsTools/NodejsTools.wxs @@ -15,6 +15,7 @@ + From c2ad6fb902f2c2a05b607889debd51be71bb9d01 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Thu, 9 Jun 2016 00:52:03 +0100 Subject: [PATCH 4/8] Factored out findTape and loadTestCases. When loading test script throws, output error and continue loading other scripts. Use strict. --- .../Nodejs/TestFrameworks/Tape/tape.js | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js index 11ab1804d..a994327ab 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js @@ -1,12 +1,11 @@ +"use strict"; + var fs = require('fs'); var path = require('path'); function find_tests(testFileList, discoverResultFile, projectFolder) { var test = findTape(projectFolder); - if (test === null) { - console.error("NTVS_ERROR:", "Couldn't find 'tape' module relative to", projectFolder); - return; - } + if (test === null) return; var harness = test.getHarness({ exit: false }); var tests = harness["_tests"]; @@ -14,19 +13,12 @@ function find_tests(testFileList, discoverResultFile, projectFolder) { var count = 0; var testList = []; testFileList.split(';').forEach(function (testFile) { - - var testCases; - process.chdir(path.dirname(testFile)); - try { - testCases = require(testFile); - } catch (ex) { - console.error("NTVS_ERROR:", ex, "in", testFile); - return; - } + var testCases = loadTestCases(testFile); + if (testCases === null) return; // continue to next testFile for (; count < tests.length; count++) { var t = tests[count]; - t._skip = true; // Don't run tests. + t._skip = true; // don't run tests testList.push({ test: t.name, suite: '', @@ -44,22 +36,13 @@ function find_tests(testFileList, discoverResultFile, projectFolder) { module.exports.find_tests = find_tests; function run_tests(testName, testFile, workingFolder, projectFolder) { - var testCases; - process.chdir(path.dirname(testFile)); - try { - testCases = require(testFile); - } catch (ex) { - console.error("NTVS_ERROR:", ex, "in", testFile); - return; - } + var testCases = loadTestCases(testFile); + if (testCases === null) return; - try { - var test = findTape(projectFolder); - if (test === null) { - console.error("NTVS_ERROR:", "Couldn't find 'tape' module relative to", projectFolder); - return; - } + var test = findTape(projectFolder); + if (test === null) return; + try { var harness = test.getHarness(); harness.only(testName); } catch (ex) { @@ -69,7 +52,22 @@ function run_tests(testName, testFile, workingFolder, projectFolder) { } module.exports.run_tests = run_tests; +function loadTestCases(testFile) { + try { + process.chdir(path.dirname(testFile)); + return require(testFile); + } catch (e) { + console.error("NTVS_ERROR:", e, "in", testFile); + return null; + } +} + function findTape(projectFolder) { - var tapePath = path.join(projectFolder, 'node_modules', 'tape'); - return require(tapePath); + try { + var tapePath = path.join(projectFolder, 'node_modules', 'tape'); + return require(tapePath); + } catch (e) { + console.error("NTVS_ERROR:", "Couldn't find 'tape' module relative to", projectFolder); + return null; + } } From 467ef2710f5c4e21d65cd15ae10241c226bba6f9 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Fri, 10 Jun 2016 00:09:46 +0100 Subject: [PATCH 5/8] Made error messages more helpful. Added InstallDirectory entry for 'tape.js'. Follow always use curly brackets convention. --- .../Nodejs/TestFrameworks/Tape/tape.js | 27 ++++++++++++++----- .../Setup/NodejsTools/NodejsToolsFiles.proj | 6 ++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js index a994327ab..5c18d10fd 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js @@ -5,7 +5,9 @@ var path = require('path'); function find_tests(testFileList, discoverResultFile, projectFolder) { var test = findTape(projectFolder); - if (test === null) return; + if (test === null) { + return; + } var harness = test.getHarness({ exit: false }); var tests = harness["_tests"]; @@ -37,16 +39,20 @@ module.exports.find_tests = find_tests; function run_tests(testName, testFile, workingFolder, projectFolder) { var testCases = loadTestCases(testFile); - if (testCases === null) return; + if (testCases === null) { + return; + } var test = findTape(projectFolder); - if (test === null) return; + if (test === null) { + return; + } try { var harness = test.getHarness(); harness.only(testName); - } catch (ex) { - console.error("NTVS_ERROR:", ex); + } catch (e) { + logError("Error running test:", testName, "in", testFile, e); return; } } @@ -57,7 +63,8 @@ function loadTestCases(testFile) { process.chdir(path.dirname(testFile)); return require(testFile); } catch (e) { - console.error("NTVS_ERROR:", e, "in", testFile); + // we would like continue discover other files, so swallow, log and continue; + logError("Test discovery error:", e, "in", testFile); return null; } } @@ -67,7 +74,13 @@ function findTape(projectFolder) { var tapePath = path.join(projectFolder, 'node_modules', 'tape'); return require(tapePath); } catch (e) { - console.error("NTVS_ERROR:", "Couldn't find 'tape' module relative to", projectFolder); + logError("Failed to find Tape package. Tape must be installed in the project locally. Mocha can be installed locally with the npm manager via solution explorer or with \".npm install tape\" via the Node.js interactive window."); return null; } } + +function logError() { + var errorArgs = Array.prototype.slice.call(arguments); + errorArgs.unshift("NTVS_ERROR:"); + console.error.apply(console, errorArgs); +} diff --git a/Nodejs/Setup/NodejsTools/NodejsToolsFiles.proj b/Nodejs/Setup/NodejsTools/NodejsToolsFiles.proj index 2eb207a93..7611868db 100644 --- a/Nodejs/Setup/NodejsTools/NodejsToolsFiles.proj +++ b/Nodejs/Setup/NodejsTools/NodejsToolsFiles.proj @@ -164,7 +164,11 @@ TestFrameworksMocha - + + + TestFrameworksTape + + Date: Fri, 10 Jun 2016 10:08:06 +0100 Subject: [PATCH 7/8] Fixed minor typo. --- .../Nodejs/Templates/Files/TypeScriptMochaUnitTest/UnitTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nodejs/Product/Nodejs/Templates/Files/TypeScriptMochaUnitTest/UnitTest.ts b/Nodejs/Product/Nodejs/Templates/Files/TypeScriptMochaUnitTest/UnitTest.ts index c8dbcaa56..226523d9e 100644 --- a/Nodejs/Product/Nodejs/Templates/Files/TypeScriptMochaUnitTest/UnitTest.ts +++ b/Nodejs/Product/Nodejs/Templates/Files/TypeScriptMochaUnitTest/UnitTest.ts @@ -7,6 +7,6 @@ describe("Test Suite 1", () => { it("Test B", () => { assert.ok(1 === 1, "This shouldn't fail"); - assert.ok(false, "This should fail ts"); + assert.ok(false, "This should fail"); }); }); From 1a908421b35bf834fd9531d3a9e5413bc839ad13 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Fri, 10 Jun 2016 12:31:46 +0100 Subject: [PATCH 8/8] Added Tape UnitTest file templates for JavaScript and TypeScript. --- Nodejs/Product/Nodejs/Nodejs.csproj | 5 ++++- .../Templates/Files/TapeUnitTest/UnitTest.js | 12 ++++++++++++ .../Files/TapeUnitTest/UnitTest.vstemplate | 18 ++++++++++++++++++ .../Files/TypeScriptTapeUnitTest/UnitTest.ts | 12 ++++++++++++ .../TypeScriptTapeUnitTest/UnitTest.vstemplate | 18 ++++++++++++++++++ Nodejs/Product/Nodejs/VSPackage.resx | 12 ++++++++++++ Nodejs/Setup/NodejsTools/NodejsToolsFiles.proj | 2 ++ 7 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 Nodejs/Product/Nodejs/Templates/Files/TapeUnitTest/UnitTest.js create mode 100644 Nodejs/Product/Nodejs/Templates/Files/TapeUnitTest/UnitTest.vstemplate create mode 100644 Nodejs/Product/Nodejs/Templates/Files/TypeScriptTapeUnitTest/UnitTest.ts create mode 100644 Nodejs/Product/Nodejs/Templates/Files/TypeScriptTapeUnitTest/UnitTest.vstemplate diff --git a/Nodejs/Product/Nodejs/Nodejs.csproj b/Nodejs/Product/Nodejs/Nodejs.csproj index c54d37f9b..4132234be 100644 --- a/Nodejs/Product/Nodejs/Nodejs.csproj +++ b/Nodejs/Product/Nodejs/Nodejs.csproj @@ -875,6 +875,10 @@ PreserveNewest true + + + + PreserveNewest true @@ -1698,7 +1702,6 @@ -