From ac0f916accca53ff48d26202495821aa91c05058 Mon Sep 17 00:00:00 2001 From: Max Peterson Date: Mon, 18 Mar 2013 10:39:05 +0000 Subject: [PATCH 1/3] Fix typo in test fixtures deifne > define. --- test/integration/fixtures/package-one-v2/main.js | 2 +- test/integration/fixtures/package-one-v3/main.js | 2 +- test/integration/fixtures/package-one/main.js | 2 +- .../fixtures/package-three-invalid-characters/main.js | 2 +- test/integration/fixtures/package-three-invalid-extjs/main.js | 2 +- test/integration/fixtures/package-two-v2/two.js | 2 +- test/integration/fixtures/package-two/two.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/integration/fixtures/package-one-v2/main.js b/test/integration/fixtures/package-one-v2/main.js index 095bf90..e608dae 100644 --- a/test/integration/fixtures/package-one-v2/main.js +++ b/test/integration/fixtures/package-one-v2/main.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package One'; }); diff --git a/test/integration/fixtures/package-one-v3/main.js b/test/integration/fixtures/package-one-v3/main.js index 095bf90..e608dae 100644 --- a/test/integration/fixtures/package-one-v3/main.js +++ b/test/integration/fixtures/package-one-v3/main.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package One'; }); diff --git a/test/integration/fixtures/package-one/main.js b/test/integration/fixtures/package-one/main.js index 095bf90..e608dae 100644 --- a/test/integration/fixtures/package-one/main.js +++ b/test/integration/fixtures/package-one/main.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package One'; }); diff --git a/test/integration/fixtures/package-three-invalid-characters/main.js b/test/integration/fixtures/package-three-invalid-characters/main.js index 1b672c9..df9ca60 100644 --- a/test/integration/fixtures/package-three-invalid-characters/main.js +++ b/test/integration/fixtures/package-three-invalid-characters/main.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package Three'; }); diff --git a/test/integration/fixtures/package-three-invalid-extjs/main.js b/test/integration/fixtures/package-three-invalid-extjs/main.js index 1b672c9..df9ca60 100644 --- a/test/integration/fixtures/package-three-invalid-extjs/main.js +++ b/test/integration/fixtures/package-three-invalid-extjs/main.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package Three'; }); diff --git a/test/integration/fixtures/package-two-v2/two.js b/test/integration/fixtures/package-two-v2/two.js index 91a2ce9..ed13094 100644 --- a/test/integration/fixtures/package-two-v2/two.js +++ b/test/integration/fixtures/package-two-v2/two.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package Two'; }); diff --git a/test/integration/fixtures/package-two/two.js b/test/integration/fixtures/package-two/two.js index 91a2ce9..ed13094 100644 --- a/test/integration/fixtures/package-two/two.js +++ b/test/integration/fixtures/package-two/two.js @@ -1,3 +1,3 @@ -deifne(['exports'], function (exports) { +define(['exports'], function (exports) { exports.name = 'Package Two'; }); From 03ebffe8b2dd55ca4ffcbd2bf81d1ddc6bab8126 Mon Sep 17 00:00:00 2001 From: Max Peterson Date: Mon, 18 Mar 2013 11:34:00 +0000 Subject: [PATCH 2/3] Add compile shim test. --- .../fixtures/package-one-shim/main.js | 3 + .../fixtures/package-one-shim/package.json | 10 ++ .../test-emptyproject-install-compile-shim.js | 124 ++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 test/integration/fixtures/package-one-shim/main.js create mode 100644 test/integration/fixtures/package-one-shim/package.json create mode 100644 test/integration/test-emptyproject-install-compile-shim.js diff --git a/test/integration/fixtures/package-one-shim/main.js b/test/integration/fixtures/package-one-shim/main.js new file mode 100644 index 0000000..08b2384 --- /dev/null +++ b/test/integration/fixtures/package-one-shim/main.js @@ -0,0 +1,3 @@ +var PackageOne = { + name: 'Package One' +} diff --git a/test/integration/fixtures/package-one-shim/package.json b/test/integration/fixtures/package-one-shim/package.json new file mode 100644 index 0000000..1058839 --- /dev/null +++ b/test/integration/fixtures/package-one-shim/package.json @@ -0,0 +1,10 @@ +{ + "name": "package-one", + "version": "0.0.1", + "description": "Test package one shim", + "jam": { + "shim": { + "exports": "PackageOne" + } + } +} diff --git a/test/integration/test-emptyproject-install-compile-shim.js b/test/integration/test-emptyproject-install-compile-shim.js new file mode 100644 index 0000000..5d7060b --- /dev/null +++ b/test/integration/test-emptyproject-install-compile-shim.js @@ -0,0 +1,124 @@ +/** + * Test description + * ================ + * + * Starting with an empty project (no package.json) + * - jam publish package-one @ 0.0.1 + * - jam publish package-two @ 0.0.1 + * - jam install package-two + * - jam compile output.js, test both modules included in output.js + */ + + +var couchdb = require('../../lib/couchdb'), + logger = require('../../lib/logger'), + env = require('../../lib/env'), + utils = require('../utils'), + async = require('async'), + http = require('http'), + path = require('path'), + ncp = require('ncp').ncp, + fs = require('fs'), + _ = require('underscore'), + vm = require('vm'); + + +var pathExists = fs.exists || path.exists; + + +logger.clean_exit = true; + +// CouchDB database URL to use for testing +var TESTDB = process.env['JAM_TEST_DB'], + BIN = path.resolve(__dirname, '../../bin/jam.js'), + ENV = {JAM_TEST: 'true', JAM_TEST_DB: TESTDB}; + +if (!TESTDB) { + throw 'JAM_TEST_DB environment variable not set'; +} + +// remove trailing-slash from TESTDB URL +TESTDB = TESTDB.replace(/\/$/, ''); + + +exports.setUp = function (callback) { + // change to integration test directory before running test + this._cwd = process.cwd(); + process.chdir(__dirname); + + // recreate any existing test db + couchdb(TESTDB).deleteDB(function (err) { + if (err && err.error !== 'not_found') { + return callback(err); + } + // create test db + couchdb(TESTDB).createDB(callback); + }); +}; + +exports.tearDown = function (callback) { + // change back to original working directory after running test + process.chdir(this._cwd); + // delete test db + couchdb(TESTDB).deleteDB(callback); +}; + + +exports['empty project'] = { + + setUp: function (callback) { + this.project_dir = path.resolve(env.temp, 'jamtest-' + Math.random()); + // set current project to empty directory + ncp('./fixtures/project-empty', this.project_dir, callback); + }, + + /* + tearDown: function (callback) { + var that = this; + // timeout to try and wait until dir is no-longer busy on windows + //utils.myrimraf(that.project_dir, callback); + }, + */ + + 'publish, install, upgrade': function (test) { + test.expect(6); + var that = this; + process.chdir(that.project_dir); + var pkgone = path.resolve(__dirname, 'fixtures', 'package-one-shim'), + pkgtwo = path.resolve(__dirname, 'fixtures', 'package-two'); + + async.series([ + async.apply(utils.runJam, ['publish', pkgone], {env: ENV}), + async.apply(utils.runJam, ['publish', pkgtwo], {env: ENV}), + async.apply( + utils.runJam, ['install', 'package-two'], {env: ENV} + ), + async.apply( + utils.runJam, ['compile', 'output.js'], {env: ENV} + ), + function (cb) { + var content = fs.readFileSync('output.js').toString(); + test.ok(/Package One/.test(content)); + test.ok(/Package Two/.test(content)); + test.ok(/requirejs/.test(content)); + test.ok(/package-one\/main/.test(content)); + test.ok(/package-two\/two/.test(content)); + // Test that the package-one shim was used. + // If the shim is used then output.js will include a definition + // of 'package-one/main' that returns the global PackageOne. + // e.g. define("package-one/main",function(e){return function(){var t,n;return t||e.PackageOne}}(this)); + // + var sandbox = {}; + vm.runInNewContext( + content + + "require(['package-one'], function (p) { p1 = p; });", + sandbox + ); + test.same(sandbox.PackageOne, sandbox.p1); + cb(); + } + ], + test.done); + } + +}; From ea2f8d171606590f0bde10968e71a384aadcb10e Mon Sep 17 00:00:00 2001 From: Max Peterson Date: Mon, 18 Mar 2013 11:35:05 +0000 Subject: [PATCH 3/3] Add shim to requirejs optimize config. --- lib/commands/compile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/commands/compile.js b/lib/commands/compile.js index a4c640f..48ecca2 100644 --- a/lib/commands/compile.js +++ b/lib/commands/compile.js @@ -216,7 +216,8 @@ exports.compile = function (opt, callback) { optimize: 'uglify', include: includes, out: opt.output, - paths: {requireLib: impl} + paths: {requireLib: impl}, + shim: require(configfile).shim }; if (opt.verbose) { config.logLevel = 0;