Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revamping the build process and tests a little so that the tests can …

…be re-used in FF's xpcshell unit tests
  • Loading branch information...
commit 4d693d2fbcb890969d4e5f2f9dbedacfa2b05755 1 parent 371e4f2
@fitzgen fitzgen authored
View
69 Makefile.dryice.js
@@ -48,7 +48,6 @@ function buildFirefox() {
roots: [ path.join(__dirname, 'lib') ]
});
- // Create SourceMapConsumer.jsm
copy({
source: [
'build/prefix-source-map.jsm',
@@ -64,20 +63,74 @@ function buildFirefox() {
dest: 'dist/SourceMap.jsm'
});
- // TODO: Create TestUtils.jsm
+ // Create dist/test/Utils.jsm
+ console.log('\nCreating dist/test/Utils.jsm');
+
+ project = copy.createCommonJsProject({
+ roots: [ __dirname, path.join(__dirname, 'lib') ]
+ });
+
+ copy({
+ source: [
+ 'build/prefix-utils.jsm',
+ 'build/assert-shim.js',
+ {
+ project: project,
+ require: [ 'test/source-map/util' ]
+ },
+ 'build/suffix-utils.jsm'
+ ],
+ filter: copy.filter.moduleDefines,
+ dest: 'dist/test/Utils.jsm'
+ });
// TODO: Loop through all the test files and make them built test files.
+
+ function isTestFile(f) {
+ return /^test\-.*?\.js/.test(f);
+ }
+
+ var testFiles = fs.readdirSync(path.join(__dirname, 'test', 'source-map')).filter(isTestFile);
+
+ testFiles.forEach(function (testFile) {
+ console.log('\nCreating', path.join('dist', 'test', testFile.replace(/\-/g, '_')));
+
+ copy({
+ source: [
+ 'build/test-prefix.js',
+ path.join('test', 'source-map', testFile),
+ 'build/test-suffix.js'
+ ],
+ filter: [
+ function (input, source) {
+ return input.replace('define(',
+ 'define("'
+ + path.join('test', 'source-map', testFile.replace(/\.js$/, ''))
+ + '", ["require", "exports", "module"], ');
+ },
+ function (input, source) {
+ return input.replace('{THIS_MODULE}', function () {
+ return "test/source-map/" + testFile.replace(/\.js$/, '');
+ });
+ }
+ ],
+ dest: path.join('dist', 'test', testFile.replace(/\-/g, '_'))
+ });
+ });
}
-var dirExists = false;
-try {
- dirExists = fs.statSync('dist').isDirectory();
-} catch (err) {}
+function ensureDir(name) {
+ var dirExists = false;
+ try {
+ dirExists = fs.statSync(name).isDirectory();
+ } catch (err) {}
-if (!dirExists) {
- fs.mkdirSync('dist', 0777);
+ if (!dirExists) {
+ fs.mkdirSync(name, 0777);
+ }
}
+ensureDir("dist/test");
buildFirefox();
buildBrowser();
buildBrowserMin();
View
89 build/assert-shim.js
@@ -0,0 +1,89 @@
+/* -*- Mode: js; js-indent-level: 2; -*- */
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+define('test/source-map/assert', ['exports'], function (exports) {
+
+ let do_throw = function (msg) {
+ throw new Error(msg);
+ };
+
+ exports.init = function (throw_fn) {
+ do_throw = throw_fn;
+ };
+
+ exports.deepEqual = function (actual, expected, msg) {
+ msg = msg || String(actual) + ' is not deepEqual to ' + String(expected);
+
+ let actualType = typeof actual;
+ let expectedType = typeof expected;
+
+ if (actualType !== expectedType) {
+ do_throw(msg);
+ }
+ else if (actualType === 'object' && actual !== null && expected !== null) {
+ let actualKeys = Object.keys(actual).sort();
+ let expectedKeys = Object.keys(expected).sort();
+
+ if (actualKeys.length !== expectedKeys.length) {
+ do_throw(msg);
+ }
+ else {
+ for (let i = 0, len = actualKeys.length; i < 0; i++) {
+ if (actualKeys[i] !== expectedKeys[i]) {
+ do_throw(msg);
+ }
+ }
+ }
+
+ actualKeys.forEach(function (k) {
+ exports.deepEqual(actual[k], expected[k], msg);
+ });
+ }
+ else {
+ exports.equal(actual, expected, msg);
+ }
+ };
+
+ exports.doesNotThrow = function (fn) {
+ try {
+ fn();
+ }
+ catch (e) {
+ do_throw(e.message);
+ }
+ };
+
+ exports.equal = function (actual, expected, msg) {
+ msg = msg || String(actual) + ' != ' + String(expected);
+ if (actual != expected) {
+ do_throw(msg);
+ }
+ };
+
+ exports.ok = function (val, msg) {
+ msg = msg || String(val) + ' is falsey';
+ if (!Boolean(val)) {
+ do_throw(msg);
+ }
+ };
+
+ exports.strictEqual = function (actual, expected, msg) {
+ msg = msg || String(actual) + ' !== ' + String(expected);
+ if (actual !== expected) {
+ do_throw(msg);
+ }
+ };
+
+ exports.throws = function (fn) {
+ try {
+ fn();
+ do_throw('Expected an error to be thrown, but it wasn\'t.');
+ }
+ catch (e) {
+ }
+ };
+
+});
View
18 build/prefix-utils.jsm
@@ -0,0 +1,18 @@
+/* -*- Mode: js; js-indent-level: 2; -*- */
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+
+/*
+ * WARNING!
+ *
+ * Do not edit this file directly, it is built from the sources at
+ * https://github.com/mozilla/source-map/
+ */
+
+Components.utils.import('resource:///modules/devtools/Require.jsm');
+Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
+
+let EXPORTED_SYMBOLS = [ "define", "runSourceMapTests" ];
View
20 build/suffix-utils.jsm
@@ -0,0 +1,20 @@
+/* -*- Mode: js; js-indent-level: 2; -*- */
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+function runSourceMapTests(modName, do_throw) {
+ let mod = require(modName);
+ let assert = require('test/source-map/assert');
+ let util = require('test/source-map/util');
+
+ assert.init(do_throw);
+
+ for (let k in mod) {
+ if (/^test/.test(k)) {
+ mod[k](assert, util);
+ }
+ }
+
+}
View
8 build/test-prefix.js
@@ -0,0 +1,8 @@
+/*
+ * WARNING!
+ *
+ * Do not edit this file directly, it is built from the sources at
+ * https://github.com/mozilla/source-map/
+ */
+
+Components.utils.import('resource://test/Utils.jsm');
View
3  build/test-suffix.js
@@ -0,0 +1,3 @@
+function run_test() {
+ runSourceMapTests('{THIS_MODULE}', do_throw);
+}
View
7 test/run-tests.js
@@ -7,6 +7,7 @@
*/
var assert = require('assert');
var fs = require('fs');
+var path = require('path');
var requirejs = require('requirejs');
requirejs.config({
@@ -16,7 +17,7 @@ requirejs.config({
nodeRequire: require
});
-requirejs(['./util'], function (util) {
+requirejs(['./source-map/util'], function (util) {
function run(tests) {
var failures = [];
@@ -67,10 +68,10 @@ requirejs(['./util'], function (util) {
}
function toModule(f) {
- return './' + f.replace(/\.js$/, '');
+ return './source-map/' + f.replace(/\.js$/, '');
}
- var requires = fs.readdirSync(__dirname).filter(isTestFile).map(toModule);
+ var requires = fs.readdirSync(path.join(__dirname, 'source-map')).filter(isTestFile).map(toModule);
requirejs(requires, function () {
View
0  test/test-array-set.js → test/source-map/test-array-set.js
File renamed without changes
View
0  test/test-base64-vlq.js → test/source-map/test-base64-vlq.js
File renamed without changes
View
0  test/test-base64.js → test/source-map/test-base64.js
File renamed without changes
View
0  test/test-binary-search.js → test/source-map/test-binary-search.js
File renamed without changes
View
0  test/test-dog-fooding.js → test/source-map/test-dog-fooding.js
File renamed without changes
View
0  test/test-source-map-consumer.js → test/source-map/test-source-map-consumer.js
File renamed without changes
View
0  test/test-source-map-generator.js → test/source-map/test-source-map-generator.js
File renamed without changes
View
0  test/test-source-node.js → test/source-map/test-source-node.js
File renamed without changes
View
0  test/util.js → test/source-map/util.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.