Permalink
Browse files

handling requirejs.config and require.config cases

  • Loading branch information...
1 parent f0c180e commit b0835fbc014104cc38dc23ce650006973a282ee4 @thlorenz committed Dec 17, 2012
Showing with 47 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +8 −5 lib/source-config.js
  3. +14 −0 test/fixtures/requirejs-config-using-require.js
  4. +24 −1 test/source-config.js
View
@@ -10,6 +10,7 @@ lib-cov
pids
logs
results
+bin/test-upgrades
npm-debug.log
node_modules/
View
@@ -2,14 +2,17 @@ var vm = require('vm');
module.exports = function sourceConfig(code) {
var config = {}
+ , requireConfig = function (config_) { config = config_; }
, sandbox = {
- requirejs: {
- config: function (config_) { config = config_; }
- }
+ requirejs: {
+ config: requireConfig
+ }
, require: function () { }
, define: function () { }
- }
- , context = vm.createContext(sandbox);
+ };
+
+ sandbox.require.config = requireConfig;
+ var context = vm.createContext(sandbox);
vm.runInContext(code, context, 'requirejs-config.vm');
@@ -0,0 +1,14 @@
+require.config({
+ jQuery: '1.7.2',
+ paths: {
+ 'jquery': 'modules/jquery'
+ },
+ map: {
+ '*': {
+ 'jquery': 'modules/adapters/jquery'
+ },
+ 'modules/adapters/jquery': {
+ 'jquery': 'jquery'
+ }
+ }
+});
View
@@ -7,7 +7,7 @@ var test = require('tap').test
, sourceConfig = require('../lib/source-config')
;
-test('sources config from given require js config code', function (t) {
+test('\nsources config from given require js config code', function (t) {
var expected = {
shim: {
handlebars: { exports: 'Handlebars' },
@@ -27,3 +27,26 @@ test('sources config from given require js config code', function (t) {
t.deepEquals(config, expected, 'sources entire config')
t.end()
})
+
+test('\nsources config from given require js config code which uses require.config', function (t) {
+ var expected = {
+ jQuery: '1.7.2',
+ paths: {
+ 'jquery': 'modules/jquery'
+ },
+ map: {
+ '*': {
+ 'jquery': 'modules/adapters/jquery'
+ },
+ 'modules/adapters/jquery': {
+ 'jquery': 'jquery'
+ }
+ }
+ }
+
+ var js = fs.readFileSync(path.join(__dirname, 'fixtures/requirejs-config-using-require.js'), 'utf-8')
+ , config = sourceConfig(js)
+
+ t.deepEquals(config, expected, 'sources entire config')
+ t.end()
+})

0 comments on commit b0835fb

Please sign in to comment.