forked from enviPath/enviPy
Current Dev State
This commit is contained in:
8
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-only-spaces.js
generated
vendored
Normal file
8
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-only-spaces.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require( 'jquery' )
|
||||
, path = require('path');
|
||||
|
||||
var go = module.exports = function () {
|
||||
return $.jquery();
|
||||
};
|
||||
8
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-only.js
generated
vendored
Normal file
8
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-only.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('jquery')
|
||||
, path = require('path');
|
||||
|
||||
var go = module.exports = function () {
|
||||
return $.jquery();
|
||||
};
|
||||
9
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-plus-non-literals.js
generated
vendored
Normal file
9
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-plus-non-literals.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var foo = require(foo),
|
||||
$ = require( 'jquery' ),
|
||||
bar = require( bar );
|
||||
|
||||
var go = module.exports = function () {
|
||||
return $.jquery();
|
||||
};
|
||||
18
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-three-d3.spread.js
generated
vendored
Normal file
18
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-three-d3.spread.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('jquery')
|
||||
, d3 = require('d3')
|
||||
// this one just here to show that other stuff doesn't get changed
|
||||
, path = require('path');
|
||||
|
||||
function getThree() {
|
||||
return (function () {
|
||||
// this one is kinda hidden
|
||||
return require('three');
|
||||
})()
|
||||
}
|
||||
|
||||
var go = module.exports = function () {
|
||||
// super hidden require for r2d3
|
||||
return { jquery: $.jquery(), three: getThree().version, d3: d3.version, r2d3: require('d3').version };
|
||||
};
|
||||
9
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-three.js
generated
vendored
Normal file
9
static/js/ketcher2/node_modules/exposify/test/fixtures/jquery-three.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('jquery')
|
||||
, three = require('three')
|
||||
, path = require('path');
|
||||
|
||||
var go = module.exports = function () {
|
||||
return { jquery: $.jquery(), three: three.version };
|
||||
};
|
||||
7
static/js/ketcher2/node_modules/exposify/test/fixtures/lodash-noconflict.js
generated
vendored
Normal file
7
static/js/ketcher2/node_modules/exposify/test/fixtures/lodash-noconflict.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
|
||||
var go = module.exports = function () {
|
||||
return _.lo;
|
||||
};
|
||||
7
static/js/ketcher2/node_modules/exposify/test/fixtures/three-only.js
generated
vendored
Normal file
7
static/js/ketcher2/node_modules/exposify/test/fixtures/three-only.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
|
||||
var go = module.exports = function () {
|
||||
return three.version;
|
||||
};
|
||||
0
static/js/ketcher2/node_modules/exposify/test/index.js
generated
vendored
Normal file
0
static/js/ketcher2/node_modules/exposify/test/index.js
generated
vendored
Normal file
20
static/js/ketcher2/node_modules/exposify/test/jquery-only-spaces.js
generated
vendored
Normal file
20
static/js/ketcher2/node_modules/exposify/test/jquery-only-spaces.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
, run = require('./util/run')
|
||||
|
||||
function jquery() { return 'jq' }
|
||||
|
||||
test('\nproviding jquery:$ and exposifying src with one jquery require that contains spaces', function (t) {
|
||||
var file = 'jquery-only-spaces.js';
|
||||
var map = { 'jquery': '$' };
|
||||
var window = { $: { jquery: jquery } };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
t.equal(main(), 'jq', 'exposes $ as jquery');
|
||||
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
42
static/js/ketcher2/node_modules/exposify/test/jquery-only.js
generated
vendored
Normal file
42
static/js/ketcher2/node_modules/exposify/test/jquery-only.js
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
, run = require('./util/run')
|
||||
|
||||
function jquery() { return 'jq' }
|
||||
|
||||
test('\nproviding jquery:$ and exposifying src with one jquery require', function (t) {
|
||||
var file = 'jquery-only.js';
|
||||
var map = { 'jquery': '$' };
|
||||
var window = { $: { jquery: jquery } };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
t.equal(main(), 'jq', 'exposes $ as jquery');
|
||||
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
|
||||
test('\nproviding map without jquery:$ and exposifying src with one jquery require', function (t) {
|
||||
var file = 'jquery-only.js';
|
||||
var map = { };
|
||||
var window = { $: { jquery: jquery } };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
t.similar(err, /module "jquery" not found from/, 'does not expose it')
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
|
||||
test('\nproviding jquery:$ but exposifying src with one three require', function (t) {
|
||||
var file = 'three-only.js';
|
||||
var map = { 'jquery': '$' };
|
||||
var window = { $: { jquery: jquery } };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
t.similar(err, /module "three" not found from/, 'does not expose three')
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
20
static/js/ketcher2/node_modules/exposify/test/jquery-plus-non-literals.js
generated
vendored
Normal file
20
static/js/ketcher2/node_modules/exposify/test/jquery-plus-non-literals.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
, run = require('./util/run')
|
||||
|
||||
function jquery() { return 'jq' }
|
||||
|
||||
test('\nproviding jquery:$ and requiring variable (non-literal) named paths', function (t) {
|
||||
var file = 'jquery-plus-non-literals.js';
|
||||
var map = { 'jquery': '$' };
|
||||
var window = { $: { jquery: jquery } };
|
||||
|
||||
run(map, file, window, {ignoreMissing: true}, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
t.equal(main(), 'jq', 'exposes $ as jquery');
|
||||
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
27
static/js/ketcher2/node_modules/exposify/test/jquery-three-d3.spread.js
generated
vendored
Normal file
27
static/js/ketcher2/node_modules/exposify/test/jquery-three-d3.spread.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
, run = require('./util/run')
|
||||
, show = require('./util/show')
|
||||
|
||||
function jquery() { return 'jq' }
|
||||
var three = { version: 'v1.1.1' };
|
||||
var d3 = { version: 'v2.1.3' };
|
||||
|
||||
test('\nproviding jquery:$ three:THREE d3:d3 and exposifying src with one jquery, multiple d3 and one three require', function (t) {
|
||||
var file = 'jquery-three-d3.spread.js';
|
||||
var map = { jquery: '$', three: 'THREE', d3: 'd3' };
|
||||
var window = { $: { jquery: jquery }, THREE: three, d3: d3 };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
var res = main()
|
||||
t.equal(res.jquery, 'jq', 'exposes $ as jquery');
|
||||
t.equal(res.three, three.version, 'exposes THREE as three whose require was very nested')
|
||||
t.equal(res.d3, d3.version, 'exposes d3')
|
||||
t.equal(res.r2d3, d3.version, 'exposes d3 which was required inline')
|
||||
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
36
static/js/ketcher2/node_modules/exposify/test/jquery-three.js
generated
vendored
Normal file
36
static/js/ketcher2/node_modules/exposify/test/jquery-three.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
, run = require('./util/run')
|
||||
, show = require('./util/show')
|
||||
|
||||
|
||||
function jquery() { return 'jq' }
|
||||
var three = { version: 'v1.1.1' };
|
||||
|
||||
test('\nproviding jquery:$ three:THREE and exposifying src with one jquery and three require', function (t) {
|
||||
var file = 'jquery-three.js';
|
||||
var map = { 'jquery': '$', 'three': 'THREE' };
|
||||
var window = { $: { jquery: jquery }, THREE: three };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
var res = main()
|
||||
t.equal(res.jquery, 'jq', 'exposes $ as jquery');
|
||||
t.equal(res.three, three.version, 'exposes THREE as three')
|
||||
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
|
||||
test('\nproviding jquery:$ and exposifying src with one jquery and three require', function (t) {
|
||||
var file = 'jquery-three.js';
|
||||
var map = { 'jquery': '$' };
|
||||
var window = { $: { jquery: jquery }, THREE: three };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
t.similar(err, /module "three" not found from/, 'does not expose three')
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
20
static/js/ketcher2/node_modules/exposify/test/lodash-noconflict.js
generated
vendored
Normal file
20
static/js/ketcher2/node_modules/exposify/test/lodash-noconflict.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/*jshint asi: true */
|
||||
|
||||
var test = require('tap').test
|
||||
, run = require('./util/run')
|
||||
, show = require('./util/show')
|
||||
|
||||
var lodash = { lo: 'and behold' }
|
||||
|
||||
test('\nproviding lodash: _.noConflict() and exposifying src with one lodash require', function (t) {
|
||||
var file = 'lodash-noconflict.js';
|
||||
var map = { 'lodash': '_.noConflict()' };
|
||||
var window = { _: { noConflict: function nodConflict() { return lodash } } };
|
||||
|
||||
run(map, file, window, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
t.equal(main(), 'and behold', 'exposes _.noConflict() as lodash');
|
||||
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
45
static/js/ketcher2/node_modules/exposify/test/transform-config.js
generated
vendored
Normal file
45
static/js/ketcher2/node_modules/exposify/test/transform-config.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var browserify = require('browserify')
|
||||
, vm = require('vm')
|
||||
, exposify = require('../');
|
||||
|
||||
var test = require('tap').test;
|
||||
|
||||
function run(config, file, window, cb) {
|
||||
|
||||
var ctx = { window: window };
|
||||
var fullPath = require.resolve('./fixtures/' + file);
|
||||
|
||||
browserify()
|
||||
.require(fullPath)
|
||||
.transform(exposify, config)
|
||||
.bundle(function (err, res) {
|
||||
if (err) return cb(err);
|
||||
try {
|
||||
var require_ = vm.runInNewContext(res, ctx);
|
||||
cb(null, require_(fullPath));
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function jquery() { return 'jq' }
|
||||
|
||||
test('\nproviding jquery:$ and exposifying src with one jquery require', function (t) {
|
||||
var file = 'jquery-only.js';
|
||||
var window = { $: { jquery: jquery } };
|
||||
|
||||
var config = {
|
||||
expose: { 'jquery': '$' }
|
||||
};
|
||||
|
||||
run(config, file, window, function (err, main) {
|
||||
if (err) { t.fail(err); return t.end(); }
|
||||
t.equal(main(), 'jq', 'exposes $ as jquery');
|
||||
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
41
static/js/ketcher2/node_modules/exposify/test/util/run.js
generated
vendored
Normal file
41
static/js/ketcher2/node_modules/exposify/test/util/run.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var browserify = require('browserify')
|
||||
, vm = require('vm')
|
||||
, exposify = require('../../')
|
||||
|
||||
module.exports = function run(map, file, window, cb) {
|
||||
exposify.config = map;
|
||||
|
||||
var ctx = { window: window };
|
||||
var fullPath = require.resolve('../fixtures/' + file);
|
||||
|
||||
// If five arguments are provided, fourth one is an object for browserify
|
||||
// options.
|
||||
var opts = {};
|
||||
if (arguments.length === 5) {
|
||||
opts = cb;
|
||||
cb = arguments[4];
|
||||
}
|
||||
|
||||
// If ignoreMissing is true, set ctx.require to a no-op. This needed for the
|
||||
// jquery-plus-non-literals test, as it has require statements that don't get
|
||||
// converted with browserify-shim.
|
||||
if ('ignoreMissing' in opts) {
|
||||
ctx.require = function() {};
|
||||
}
|
||||
|
||||
browserify(opts)
|
||||
.require(fullPath)
|
||||
.transform(exposify)
|
||||
.bundle(function (err, res) {
|
||||
if (err) return cb(err);
|
||||
try {
|
||||
var require_ = vm.runInNewContext(res, ctx);
|
||||
cb(null, require_(fullPath));
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
15
static/js/ketcher2/node_modules/exposify/test/util/show.js
generated
vendored
Normal file
15
static/js/ketcher2/node_modules/exposify/test/util/show.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs')
|
||||
, expose = require('../../').expose
|
||||
|
||||
// supports same signature as run in order to quickly troubleshoot by simply changing 'run' to 'show'
|
||||
module.exports = function show(map, file, _, cb) {
|
||||
var fullPath = require.resolve('../fixtures/' + file);
|
||||
var src = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
var res = expose(map, src);
|
||||
if (cb) cb(null, res);
|
||||
console.error(res);
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user