From 853a1e575a04eb2b9c6d827655c2861fb865b468 Mon Sep 17 00:00:00 2001 From: James Long Date: Thu, 28 Apr 2016 22:34:31 -0400 Subject: [PATCH 1/4] use ff-devtools-libs module name directly --- .babelrc | 4 +++ package.json | 3 +-- public/js/actions/breakpoints.js | 6 ++--- public/js/actions/event-listeners.js | 4 +-- public/js/actions/sources.js | 10 ++++---- public/js/actions/tabs.js | 4 +-- public/js/actions/tests/breakpoints.js | 30 +++++++++++++++++++++++ public/js/actions/tests/loadSourceText.js | 4 +-- public/js/client.js | 8 +++--- public/js/create-store.js | 8 +++--- public/js/prefs.js | 2 +- webpack.config.js | 7 ++---- 12 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 .babelrc create mode 100644 public/js/actions/tests/breakpoints.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000..58831a5cbd --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ "plugins": ["transform-es2015-block-scoping", + "transform-es2015-destructuring", + "transform-es2015-parameters", + "transform-es2015-spread"] } diff --git a/package.json b/package.json index 1146f3677b..8764e1b368 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "co": "=4.6.0", "codemirror": "^5.1.0", "express": "^4.13.4", - "ff-devtools-libs": "^0.1.1", + "ff-devtools-libs": "=0.1.6", "immutable": "^3.7.6", "json-loader": "^0.5.4", "karma": "^0.13.22", @@ -38,7 +38,6 @@ "babel": "^6.5.2", "babel-core": "^6.7.6", "babel-loader": "^6.2.4", - "babel-polyfill": "^6.7.4", "babel-preset-es2015": "^6.6.0", "css-loader": "^0.23.1", "eslint": "^2.7.0", diff --git a/public/js/actions/breakpoints.js b/public/js/actions/breakpoints.js index 91aec4cc3a..876d0fb35a 100644 --- a/public/js/actions/breakpoints.js +++ b/public/js/actions/breakpoints.js @@ -3,13 +3,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; -const promise = require("devtools/sham/promise"); +const promise = require("ff-devtools-libs/sham/promise"); const constants = require("../constants"); -const { PROMISE } = require("devtools/client/shared/redux/middleware/promise"); +const { PROMISE } = require("ff-devtools-libs/client/shared/redux/middleware/promise"); const { getSource, getBreakpoint, getBreakpoints } = require("../selectors"); -const { Task } = require("devtools/sham/task"); +const { Task } = require("ff-devtools-libs/sham/task"); const { fromJS } = require("immutable"); // Because breakpoints are just simple data structures, we still need diff --git a/public/js/actions/event-listeners.js b/public/js/actions/event-listeners.js index 768fbd2a92..dbb930cebc 100644 --- a/public/js/actions/event-listeners.js +++ b/public/js/actions/event-listeners.js @@ -7,8 +7,8 @@ const constants = require("../constants"); const { asPaused } = require("../util/utils"); -const { reportException } = require("devtools/shared/DevToolsUtils"); -const { Task } = require("devtools/sham/task"); +const { reportException } = require("ff-devtools-libs/shared/DevToolsUtils"); +const { Task } = require("ff-devtools-libs/sham/task"); // delay is in ms const FETCH_EVENT_LISTENERS_DELAY = 200; diff --git a/public/js/actions/sources.js b/public/js/actions/sources.js index 34f919fb9a..f5bb0fc854 100644 --- a/public/js/actions/sources.js +++ b/public/js/actions/sources.js @@ -3,11 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; -const promise = require("devtools/sham/promise"); -const { dumpn } = require("devtools/shared/DevToolsUtils"); -const { PROMISE } = require("devtools/client/shared/redux/middleware/promise"); -const { Task } = require("devtools/sham/task"); -const SourceUtils = require("devtools/client/shared/source-utils"); +const promise = require("ff-devtools-libs/sham/promise"); +const { dumpn } = require("ff-devtools-libs/shared/DevToolsUtils"); +const { PROMISE } = require("ff-devtools-libs/client/shared/redux/middleware/promise"); +const { Task } = require("ff-devtools-libs/sham/task"); +const SourceUtils = require("ff-devtools-libs/client/shared/source-utils"); const { getSource, getSourceText } = require("../selectors"); const constants = require("../constants"); diff --git a/public/js/actions/tabs.js b/public/js/actions/tabs.js index 4d4d97206b..77df06e31e 100644 --- a/public/js/actions/tabs.js +++ b/public/js/actions/tabs.js @@ -3,8 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* global window */ "use strict"; -const { Task } = require("devtools/sham/task"); -const { PROMISE } = require("devtools/client/shared/redux/middleware/promise"); +const { Task } = require("ff-devtools-libs/sham/task"); +const { PROMISE } = require("ff-devtools-libs/client/shared/redux/middleware/promise"); const { connectToTab} = require("../client"); const constants = require("../constants"); diff --git a/public/js/actions/tests/breakpoints.js b/public/js/actions/tests/breakpoints.js new file mode 100644 index 0000000000..bd0a5775b7 --- /dev/null +++ b/public/js/actions/tests/breakpoints.js @@ -0,0 +1,30 @@ +"use strict"; + +const { createStore } = require("../../util/test-head"); +const { Task } = require("ff-devtools-libs/sham/task"); +// const expect = require("expect.js"); + +const simpleMockThreadClient = { + source: function(form) { + return { + setBreakpoint: args => { + return new Promise((resolve, reject) => { + resolve({}, { + actor: form.actor + }); + }); + } + }; + } +}; + +describe("breakpoints", () => { + it("should add a breakpoint", () => { + Task.spawn(function* () { + const store = createStore(simpleMockThreadClient); + return store; + // yield actions.addBreakpoint({ line: 5 }); + // expect(queries.getBreakpoints(store.getState()).length).to.be(2); + }); + }); +}); diff --git a/public/js/actions/tests/loadSourceText.js b/public/js/actions/tests/loadSourceText.js index caa8d37c46..554375d1b5 100644 --- a/public/js/actions/tests/loadSourceText.js +++ b/public/js/actions/tests/loadSourceText.js @@ -1,7 +1,7 @@ "use strict"; -const promise = require("devtools/sham/promise"); -const { Task } = require("devtools/sham/task"); +const promise = require("ff-devtools-libs/sham/promise"); +const { Task } = require("ff-devtools-libs/sham/task"); const expect = require("expect.js"); const { actions, selectors, createStore } = require("../../util/test-head"); diff --git a/public/js/client.js b/public/js/client.js index 888cf8bd63..ca6de87271 100644 --- a/public/js/client.js +++ b/public/js/client.js @@ -1,9 +1,9 @@ "use strict"; -const { DebuggerClient } = require("devtools/shared/client/main"); -const { DebuggerTransport } = require("devtools/transport/transport"); -const { TargetFactory } = require("devtools/client/framework/target"); -const promise = require("devtools/sham/promise"); +const { DebuggerClient } = require("ff-devtools-libs/shared/client/main"); +const { DebuggerTransport } = require("ff-devtools-libs/transport/transport"); +const { TargetFactory } = require("ff-devtools-libs/client/framework/target"); +const promise = require("ff-devtools-libs/sham/promise"); let currentClient = null; let currentThreadClient = null; diff --git a/public/js/create-store.js b/public/js/create-store.js index 7682d0e8d4..882f2ac736 100644 --- a/public/js/create-store.js +++ b/public/js/create-store.js @@ -5,10 +5,10 @@ const { createStore, applyMiddleware } = require("redux"); const { thunk } = require("./util/thunk-middleware"); -const { waitUntilService } = require("devtools/client/shared/redux/middleware/wait-service"); -const { log } = require("devtools/client/shared/redux/middleware/log"); -const { promise } = require("devtools/client/shared/redux/middleware/promise"); -const { history } = require("devtools/client/shared/redux/middleware/history"); +const { waitUntilService } = require("ff-devtools-libs/client/shared/redux/middleware/wait-service"); +const { log } = require("ff-devtools-libs/client/shared/redux/middleware/log"); +const { promise } = require("ff-devtools-libs/client/shared/redux/middleware/promise"); +const { history } = require("ff-devtools-libs/client/shared/redux/middleware/history"); /** * This creates a dispatcher with all the standard middleware in place diff --git a/public/js/prefs.js b/public/js/prefs.js index 9b826f2753..c8ac648da2 100644 --- a/public/js/prefs.js +++ b/public/js/prefs.js @@ -1,7 +1,7 @@ /* eslint max-len: [2, 90] */ "use strict"; -const { PrefsHelper } = require("devtools/client/shared/prefs"); +const { PrefsHelper } = require("ff-devtools-libs/client/shared/prefs"); /** * Shortcuts for accessing various debugger preferences. diff --git a/webpack.config.js b/webpack.config.js index 63576b4aec..56e40d18a5 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -18,11 +18,8 @@ let config = { filename: "bundle.js" }, resolve: { - alias: { - "devtools": "ff-devtools-libs", - "sdk": "ff-devtools-libs/sdk" - }, - extensions: ["", ".js", ".jsm"], + // This is required to allow ff-devtools-libs to resolve modules + // to itself (all of its requires are absolute) root: path.join(__dirname, "node_modules") }, module: { From 13a89aed1bd5037ea01b013bc2628537280d01d4 Mon Sep 17 00:00:00 2001 From: James Long Date: Thu, 28 Apr 2016 22:35:01 -0400 Subject: [PATCH 2/4] use mocha directly to run tests --- bin/test-node | 76 --------------------------------------------------- package.json | 3 +- 2 files changed, 2 insertions(+), 77 deletions(-) delete mode 100755 bin/test-node diff --git a/bin/test-node b/bin/test-node deleted file mode 100755 index 2c2a858d62..0000000000 --- a/bin/test-node +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env node -"use strict"; - -const webpack = require("webpack"); -const join = require("path").join; -const resolve = require("path").resolve; -const projectWebpackConfig = require("../webpack.config"); -const Mocha = require("mocha"); -const getTestPaths = require("./getTestPaths"); - -const BUILD_DIR = join(__dirname, "../public/build"); - -function setupWebpackConfig(webpackConfig, testPaths) { - return Object.assign({}, webpackConfig, { - entry: ["babel-polyfill"].concat(testPaths.map((path) => resolve(path))), - - output: { - path: BUILD_DIR, - filename: "test-bundle.js" - }, - - module: { - loaders: [ - { - test: /.js$/, - loader: "babel-loader", - exclude: (path) => { - return path.includes("node_modules") - && !path.includes("ff-devtools-libs"); - }, - query: { - presets: ["es2015", "stage-0"] - } - }, - { - test: /\.json$/, - loader: "json-loader" - } - ] - }, - devtool: null - }); -} - -function runMocha() { - mocha.addFile(join(BUILD_DIR, "test-bundle.js")); - - mocha.run(function(failures) { - process.on("exit", function() { - process.exit(failures); - }); - }); -} - -function runWebpack(beforeBuild, afterBuild) { - beforeBuild(); - webpack(webpackConfig).run((err, stats) => { - if (err) { - console.log("ERROR", err); - } else if (stats.compilation.errors.length) { - console.log(stats.toString({ colors: true })); - } else { - afterBuild(); - } - }); -} - -const dir = process.argv.slice(2)[0]; -const mocha = new Mocha(); -const testPaths = getTestPaths(dir); -const webpackConfig = setupWebpackConfig(projectWebpackConfig, testPaths); - -runWebpack( - () => {}, - () => runMocha() -); diff --git a/package.json b/package.json index 8764e1b368..cd07d266a3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "start": "firefox-proxy & node bin/server", "lint-css": "stylelint public/js/components/*.css", "lint-js": "eslint public/js", - "test": "./bin/test-node public/js", + "test": "mocha --compilers js:babel-register public/js/**/tests/*", + "test-paths": "mocha --compilers js:babel-register", "test-browser": "./bin/server-browser-test.js", "test-karma": "./node_modules/.bin/karma start --single-run", "storybook": "start-storybook -p 9001 -s public" From 515728cfa3ca0daded3a8d80ee40731e52f92c81 Mon Sep 17 00:00:00 2001 From: James Long Date: Thu, 28 Apr 2016 23:24:11 -0400 Subject: [PATCH 3/4] add babel plugins and babel-register for running tests under node --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cd07d266a3..48724f0c21 100644 --- a/package.json +++ b/package.json @@ -39,13 +39,18 @@ "babel": "^6.5.2", "babel-core": "^6.7.6", "babel-loader": "^6.2.4", + "babel-plugin-transform-es2015-block-scoping": "^6.7.1", + "babel-plugin-transform-es2015-destructuring": "^6.6.5", + "babel-plugin-transform-es2015-parameters": "^6.7.0", + "babel-plugin-transform-es2015-spread": "^6.6.5", "babel-preset-es2015": "^6.6.0", + "babel-register": "^6.7.2", "css-loader": "^0.23.1", "eslint": "^2.7.0", "eslint-plugin-mozilla": "0.0.3", "eslint-plugin-react": "^5.0.1", - "extract-text-webpack-plugin": "^1.0.1", "expect.js": "^0.3.1", + "extract-text-webpack-plugin": "^1.0.1", "karma-chrome-launcher": "^0.2.3", "karma-firefox-launcher": "^0.1.7", "karma-mocha": "^0.2.2", From fdb624e8c50fe15977319d3bd49478c67aad3fab Mon Sep 17 00:00:00 2001 From: James Long Date: Fri, 29 Apr 2016 15:04:54 -0400 Subject: [PATCH 4/4] use webpack when running karma tests --- karma.conf.js | 31 +++++++++++++++++++++++++------ package.json | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index b49cec91ab..83abead88d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,12 +1,27 @@ "use strict"; +var webpackConfig = require('./webpack.config.js'); +webpackConfig.entry = {}; + +// Compile with babel to support older browsers. We may be able to +// remove this if we can use latest versions that have enough ES6 +// support. +webpackConfig.module.loaders.push({ + test: /\.js$/, + exclude: /(node_modules|bower_components)/, + loader: "babel", + query: { + presets: ["es2015"], + plugins: ["transform-runtime"] + } +}); + module.exports = function(config) { - const configuration = { + config.set({ basePath: "", frameworks: ["mocha"], files: [ - // Uses the node test runner because babel is required - "public/build/test-bundle.js" + "./public/js/**/tests/*" ], exclude: [], preprocessors: {}, @@ -17,8 +32,12 @@ module.exports = function(config) { logLevel: config.LOG_INFO, autoWatch: false, singleRun: false, - concurrency: Infinity - }; + concurrency: Infinity, + + preprocessors: { + "./public/js/**/tests/*": ['webpack'] + }, - config.set(configuration); + webpack: webpackConfig + }); }; diff --git a/package.json b/package.json index 48724f0c21..9763f69059 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "babel-plugin-transform-es2015-destructuring": "^6.6.5", "babel-plugin-transform-es2015-parameters": "^6.7.0", "babel-plugin-transform-es2015-spread": "^6.6.5", + "babel-plugin-transform-runtime": "^6.7.5", "babel-preset-es2015": "^6.6.0", "babel-register": "^6.7.2", "css-loader": "^0.23.1", @@ -54,6 +55,7 @@ "karma-chrome-launcher": "^0.2.3", "karma-firefox-launcher": "^0.1.7", "karma-mocha": "^0.2.2", + "karma-webpack": "^1.7.0", "rimraf": "^2.5.2", "style-loader": "^0.13.1" }