-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·102 lines (70 loc) · 2.97 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
require('chai').should()
const R = require('./folder/node_modules/ramda')
const fastRequire = R.pipe(R.tap(x => console.log('fastRequire(', x, ')')), require('./index'))
const cp = require('child_process')
cp.execSync('rm -rf no_node_modules/node_modules')
const basic = fastRequire()
basic.should.have.property('chai')
global.should.not.have.property('chai')
const withoutChai = fastRequire({without: ['chai']})
withoutChai.should.not.have.property('chai')
withoutChai.should.be.empty
global.should.not.have.property('chai')
const chaiAsNotChai = fastRequire({as: {chai: 'notChai'}})
chaiAsNotChai.should.not.have.property('chai')
chaiAsNotChai.should.have.property('notChai')
global.should.not.have.property('chai')
const search = fastRequire({search: ['.', 'folder']})
search.should.have.property('ramda')
search.should.have.property('lodash')
search.should.have.property('underscore')
search.should.have.property('chai')
global.should.not.have.property('chai')
global.should.not.have.property('lodash')
global.should.not.have.property('underscore')
global.should.not.have.property('ramda')
const onlyFolder = fastRequire({search: ['folder']})
onlyFolder.should.have.property('ramda')
onlyFolder.should.have.property('lodash')
onlyFolder.should.have.property('underscore')
onlyFolder.should.not.have.property('chai')
global.should.not.have.property('chai')
global.should.not.have.property('lodash')
global.should.not.have.property('underscore')
global.should.not.have.property('ramda')
const onlyRamda = fastRequire({search: ['folder'], only: ['ramda']})
onlyRamda.should.have.property('ramda')
onlyRamda.should.not.have.property('lodash')
onlyRamda.should.not.have.property('underscore')
onlyRamda.should.not.have.property('chai')
const ramdaToRoot = fastRequire({toRoot: ['ramda'], search: ['folder']})
ramdaToRoot.should.not.have.property('ramda')
ramdaToRoot.should.have.property('lodash')
ramdaToRoot.should.have.property('underscore')
for (const f in R) {
ramdaToRoot.should.have.property(f)
if (['toString'].indexOf(f) == -1)
global.should.not.have.property(f)
}
const ramdaToGlobal = fastRequire({toRoot: ['ramda'], search: ['folder'], global: true})
ramdaToGlobal.should.not.have.property('ramda')
global.should.not.have.property('ramda')
ramdaToGlobal.should.have.property('lodash')
global.should.have.property('lodash')
ramdaToGlobal.should.have.property('underscore')
global.should.have.property('underscore')
for (const f in R)
global.should.have.property(f)
cp.execSync('rm -rf no_node_modules/node_modules; true')
// const install = fastRequire({install: true, search: ['no_node_modules']})
//
// install.should.have.property('fastRequire')
const _require = fastRequire({require: ['fs']})
_require.should.have.property('fs')
const patch = fastRequire({patch: {chai: x => {
x.patchedMethod = () => 'patched return'
return x
}}})
String(patch.chai.patchedMethod()).should.equal('patched return')
console.log(require('fs').readFileSync(__filename, 'utf-8'))