forked from enviPath/enviPy
Current Dev State
This commit is contained in:
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/a/a1.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/a/a1.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'a1';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/a/a2.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/a/a2.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'a2';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b1.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b1.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'b1';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b2.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b2.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'b2';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b_b-b/_b.b1.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b_b-b/_b.b1.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = '_b.b1';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b_b-b/b.b2.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/deep/b/b_b-b/b.b2.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'b.b2';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/random.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/random.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = Math.random();
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/a.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/a.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'a';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/b.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/b.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'b';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/c.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/c.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 'c';
|
||||
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/d.js
generated
vendored
Normal file
2
static/js/ketcher2/node_modules/require-glob/test/fixtures/shallow/d.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = { e: 'e' };
|
||||
232
static/js/ketcher2/node_modules/require-glob/test/require-glob.js
generated
vendored
Normal file
232
static/js/ketcher2/node_modules/require-glob/test/require-glob.js
generated
vendored
Normal file
@ -0,0 +1,232 @@
|
||||
import path from 'path';
|
||||
import test from 'ava';
|
||||
import requireGlob from '../src/require-glob';
|
||||
|
||||
test('should require nothing', async t => {
|
||||
const bogusA = await requireGlob('./fixtures/bogu*.js');
|
||||
const bogusB = requireGlob.sync('./fixtures/bogu*.js');
|
||||
|
||||
t.deepEqual(bogusA, {});
|
||||
t.deepEqual(bogusB, {});
|
||||
});
|
||||
|
||||
test('should require a module', async t => {
|
||||
const oneA = await requireGlob('./fixtures/rand*.js');
|
||||
const oneB = requireGlob.sync('./fixtures/rand*.js');
|
||||
|
||||
t.is(typeof oneA.random, 'number');
|
||||
t.is(typeof oneB.random, 'number');
|
||||
});
|
||||
|
||||
test('should require multiple modules', async t => {
|
||||
const shallowA = await requireGlob('./fixtures/shallow/**/*.js');
|
||||
const shallowB = requireGlob.sync('./fixtures/shallow/**/*.js');
|
||||
const expected = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
d: {
|
||||
e: 'e'
|
||||
}
|
||||
};
|
||||
|
||||
t.deepEqual(shallowA, expected);
|
||||
t.deepEqual(shallowB, expected);
|
||||
});
|
||||
|
||||
test('should require nested modules', async t => {
|
||||
const deepA = await requireGlob('./fixtures/deep/**/*.js');
|
||||
const deepB = requireGlob.sync('./fixtures/deep/**/*.js');
|
||||
const expected = {
|
||||
a: {
|
||||
a1: 'a1',
|
||||
a2: 'a2'
|
||||
},
|
||||
b: {
|
||||
b_bB: { // eslint-disable-line camelcase
|
||||
_bB1: '_b.b1',
|
||||
bB2: 'b.b2'
|
||||
},
|
||||
b1: 'b1',
|
||||
b2: 'b2'
|
||||
}
|
||||
};
|
||||
|
||||
t.deepEqual(deepA, expected);
|
||||
t.deepEqual(deepB, expected);
|
||||
});
|
||||
|
||||
test('should require multiple patterns', async t => {
|
||||
const deep = await requireGlob([
|
||||
'./fixtures/{deep,shallow}/**/*.js',
|
||||
'!./**/a*'
|
||||
]);
|
||||
|
||||
const expected = {
|
||||
deep: {
|
||||
b: {
|
||||
b_bB: { // eslint-disable-line camelcase
|
||||
_bB1: '_b.b1',
|
||||
bB2: 'b.b2'
|
||||
},
|
||||
b1: 'b1',
|
||||
b2: 'b2'
|
||||
}
|
||||
},
|
||||
shallow: {
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
d: {
|
||||
e: 'e'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
t.deepEqual(deep, expected);
|
||||
});
|
||||
|
||||
test('should use custom cwd', async t => {
|
||||
const deep = await requireGlob('./test/**/deep/**/*.js', {
|
||||
cwd: path.dirname(__dirname)
|
||||
});
|
||||
|
||||
const expected = {
|
||||
fixtures: {
|
||||
deep: {
|
||||
a: {
|
||||
a1: 'a1',
|
||||
a2: 'a2'
|
||||
},
|
||||
b: {
|
||||
b_bB: { // eslint-disable-line camelcase
|
||||
_bB1: '_b.b1',
|
||||
bB2: 'b.b2'
|
||||
},
|
||||
b1: 'b1',
|
||||
b2: 'b2'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
t.deepEqual(deep, expected);
|
||||
});
|
||||
|
||||
test('should use custom base', async t => {
|
||||
const deep = await requireGlob('./fixtures/deep/**/*.js', {
|
||||
base: path.join(__dirname, 'fixtures')
|
||||
});
|
||||
|
||||
const expected = {
|
||||
deep: {
|
||||
a: {
|
||||
a1: 'a1',
|
||||
a2: 'a2'
|
||||
},
|
||||
b: {
|
||||
b_bB: { // eslint-disable-line camelcase
|
||||
_bB1: '_b.b1',
|
||||
bB2: 'b.b2'
|
||||
},
|
||||
b1: 'b1',
|
||||
b2: 'b2'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
t.deepEqual(deep, expected);
|
||||
});
|
||||
|
||||
test('should bust cache', async t => {
|
||||
const a = await requireGlob('./fixtures/rand*.js');
|
||||
const b = await requireGlob('./fixtures/rand*.js');
|
||||
const c = await requireGlob('./fixtures/rand*.js', {bustCache: true});
|
||||
const d = await requireGlob('./fixtures/rand*.js', {bustCache: true});
|
||||
const e = await requireGlob('./fixtures/rand*.js');
|
||||
|
||||
t.is(a.random, b.random);
|
||||
t.not(b.random, c.random);
|
||||
t.not(c.random, d.random);
|
||||
t.is(d.random, e.random);
|
||||
});
|
||||
|
||||
test('should use custom mapper', async t => {
|
||||
const deep = requireGlob.sync('./fixtures/deep/**/*.js', {
|
||||
mapper: function (options, filePath, i) {
|
||||
switch (i) {
|
||||
// The reducer expects path and export values
|
||||
case 0:
|
||||
return null;
|
||||
|
||||
case 1:
|
||||
return {path: filePath};
|
||||
|
||||
case 2:
|
||||
return {exports: i};
|
||||
|
||||
// The reducer expects a path that results in a property name
|
||||
case 3:
|
||||
return {path: '/', exports: i};
|
||||
|
||||
// Like this
|
||||
default:
|
||||
return {
|
||||
path: path.basename(filePath).toUpperCase(),
|
||||
exports: i
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const expected = {
|
||||
B1: 4,
|
||||
B2: 5
|
||||
};
|
||||
|
||||
t.deepEqual(deep, expected);
|
||||
});
|
||||
|
||||
test('should use custom reducer', async t => {
|
||||
const deep = await requireGlob('./fixtures/deep/**/*.js', {
|
||||
reducer: function (options, tree, file) {
|
||||
// The tree is an object by default
|
||||
if (!Array.isArray(tree)) {
|
||||
tree = [];
|
||||
}
|
||||
|
||||
tree.push(file.exports);
|
||||
|
||||
return tree;
|
||||
}
|
||||
});
|
||||
|
||||
const expected = [
|
||||
'a1',
|
||||
'a2',
|
||||
'_b.b1',
|
||||
'b.b2',
|
||||
'b1',
|
||||
'b2'
|
||||
];
|
||||
|
||||
t.deepEqual(deep, expected);
|
||||
});
|
||||
|
||||
test('should use custom keygen', async t => {
|
||||
const deep = await requireGlob('./fixtures/deep/**/*.js', {
|
||||
keygen: function (options, file) {
|
||||
return file.path.replace(file.base + '/', '');
|
||||
}
|
||||
});
|
||||
|
||||
const expected = {
|
||||
'a/a1.js': 'a1',
|
||||
'a/a2.js': 'a2',
|
||||
'b/b_b-b/_b.b1.js': '_b.b1',
|
||||
'b/b_b-b/b.b2.js': 'b.b2',
|
||||
'b/b1.js': 'b1',
|
||||
'b/b2.js': 'b2'
|
||||
};
|
||||
|
||||
t.deepEqual(deep, expected);
|
||||
});
|
||||
Reference in New Issue
Block a user