From b519a5ec586ac7c19f1b021b90bca2fb16fa31b0 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Thu, 5 Oct 2017 10:39:22 -0700 Subject: [PATCH] Fix firestore VSCode scripts --- .vscode/launch.json | 31 ++++++++++++++----- packages/firestore/karma.conf.js | 12 ++++++- packages/firestore/package.json | 3 +- .../{browser => integration}/bootstrap.ts | 2 +- packages/firestore/test/unit/bootstrap.ts | 26 ++++++++++++++++ 5 files changed, 64 insertions(+), 10 deletions(-) rename packages/firestore/test/{browser => integration}/bootstrap.ts (92%) create mode 100644 packages/firestore/test/unit/bootstrap.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index e9ab7d0002e..2af7c76aa00 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,24 +8,41 @@ "type": "node", "request": "launch", "name": "Firestore Unit Tests (Node)", - "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js", - "args": ["test", "--suite=firestore/unit/", "--env=node"], - "port": 9229, + "program": "${workspaceRoot}/packages/firestore/node_modules/.bin/_mocha", + "cwd": "${workspaceRoot}/packages/firestore", + "args": [ + "--compilers", "ts:ts-node/register", + "-r", "src/platform_node/node_init.ts", + "--retries", "5", + "--timeout", "5000", + "test/{,!(integration|browser)/**/}*.test.ts" + ], + "sourceMaps": true, "protocol": "inspector" }, { "type": "node", "request": "launch", "name": "Firestore Unit Tests (Browser)", - "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js", - "args": ["test", "--suite=firestore/unit/", "--env=browser", "--debug"] + "program": "${workspaceRoot}/packages/firestore/node_modules/.bin/karma", + "cwd": "${workspaceRoot}/packages/firestore", + "args": [ + "start", + "--testFiles", "test/unit/bootstrap.ts", + "--browsers", "Chrome" + ] }, { "type": "node", "request": "launch", "name": "Firestore Integration Tests (Browser)", - "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js", - "args": ["test", "--suite=firestore/integration", "--env=browser", "--debug"] + "program": "${workspaceRoot}/packages/firestore/node_modules/.bin/karma", + "cwd": "${workspaceRoot}/packages/firestore", + "args": [ + "start", + "--testFiles", "test/integration/bootstrap.ts", + "--browsers", "Chrome" + ] } ] } diff --git a/packages/firestore/karma.conf.js b/packages/firestore/karma.conf.js index b06e4d350c7..28ef08bc984 100644 --- a/packages/firestore/karma.conf.js +++ b/packages/firestore/karma.conf.js @@ -17,11 +17,21 @@ const karma = require('karma'); const path = require('path'); const karmaBase = require('../../config/karma.base'); +const { argv } = require('yargs'); + +const testFiles = (files => { + if (!files) return; + if (Array.isArray(files)) return files.map(file => ({ pattern: file })); + return [{ pattern: files }]; +})(argv.testFiles); module.exports = function(config) { const karmaConfig = Object.assign({}, karmaBase, { // files to load into karma - files: [{ pattern: `test/browser/bootstrap.ts` }], + files: testFiles ? testFiles : [ + { pattern: `test/unit/bootstrap.ts` }, + { pattern: `test/integration/bootstrap.ts` }, + ], // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha'], diff --git a/packages/firestore/package.json b/packages/firestore/package.json index c75487f647b..673ca356dd1 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -43,6 +43,7 @@ "ts-loader": "^2.3.4", "ts-node": "^3.3.0", "typescript": "^2.4.2", - "webpack": "^3.5.5" + "webpack": "^3.5.5", + "yargs": "^9.0.1" } } diff --git a/packages/firestore/test/browser/bootstrap.ts b/packages/firestore/test/integration/bootstrap.ts similarity index 92% rename from packages/firestore/test/browser/bootstrap.ts rename to packages/firestore/test/integration/bootstrap.ts index 31686dc2354..6b4d37d990b 100644 --- a/packages/firestore/test/browser/bootstrap.ts +++ b/packages/firestore/test/integration/bootstrap.ts @@ -22,5 +22,5 @@ import '../../src/platform_browser/browser_init'; * Taken from karma-webpack source: * https://github.com/webpack-contrib/karma-webpack#alternative-usage */ -var testsContext = (require as any).context('..', true, /.test$/); +var testsContext = (require as any).context('.', true, /.test$/); testsContext.keys().forEach(testsContext); diff --git a/packages/firestore/test/unit/bootstrap.ts b/packages/firestore/test/unit/bootstrap.ts new file mode 100644 index 00000000000..6b4d37d990b --- /dev/null +++ b/packages/firestore/test/unit/bootstrap.ts @@ -0,0 +1,26 @@ +/** + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import '../../src/platform_browser/browser_init'; + +/** + * This will include all of the test files and compile them as needed + * + * Taken from karma-webpack source: + * https://github.com/webpack-contrib/karma-webpack#alternative-usage + */ +var testsContext = (require as any).context('.', true, /.test$/); +testsContext.keys().forEach(testsContext);