Skip to content
This repository was archived by the owner on Aug 7, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/commands/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/integration/fixtures/package-one-shim/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var PackageOne = {
name: 'Package One'
}
10 changes: 10 additions & 0 deletions test/integration/fixtures/package-one-shim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "package-one",
"version": "0.0.1",
"description": "Test package one shim",
"jam": {
"shim": {
"exports": "PackageOne"
}
}
}
2 changes: 1 addition & 1 deletion test/integration/fixtures/package-one-v2/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package One';
});
2 changes: 1 addition & 1 deletion test/integration/fixtures/package-one-v3/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package One';
});
2 changes: 1 addition & 1 deletion test/integration/fixtures/package-one/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package One';
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package Three';
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package Three';
});
2 changes: 1 addition & 1 deletion test/integration/fixtures/package-two-v2/two.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package Two';
});
2 changes: 1 addition & 1 deletion test/integration/fixtures/package-two/two.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deifne(['exports'], function (exports) {
define(['exports'], function (exports) {
exports.name = 'Package Two';
});
124 changes: 124 additions & 0 deletions test/integration/test-emptyproject-install-compile-shim.js
Original file line number Diff line number Diff line change
@@ -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);
}

};