1 | escodegen = require 'escodegen'
|
2 | fs = require 'scopedfs'
|
3 | path = require 'path'
|
4 | vm = require 'vm'
|
5 |
|
6 | global[name] = func for name, func of require 'assert'
|
7 |
|
8 |
|
9 | egal = (a, b) ->
|
10 | if a is b
|
11 | a isnt 0 or 1/a is 1/b
|
12 | else
|
13 | a isnt a and b isnt b
|
14 |
|
15 |
|
16 | arrayEgal = (a, b) ->
|
17 | if egal a, b then yes
|
18 | else if (Array.isArray a) and Array.isArray b
|
19 | return no unless a.length is b.length
|
20 | return no for el, idx in a when not arrayEgal el, b[idx]
|
21 | yes
|
22 |
|
23 | inspect = (o) -> (require 'util').inspect o, no, 2, yes
|
24 | global.eq = (a, b, msg) -> ok (egal a, b), msg ? "#{inspect a} === #{inspect b}"
|
25 | global.arrayEq = (a, b, msg) -> ok (arrayEgal a,b), msg ? "#{inspect a} === #{inspect b}"
|
26 |
|
27 | FIXTURES_DIR = path.join __dirname, 'fixtures'
|
28 | sfs = fs.scoped FIXTURES_DIR
|
29 | sfs.reset = ->
|
30 | fs.rmrfSync FIXTURES_DIR
|
31 | fs.mkdirpSync FIXTURES_DIR
|
32 | do sfs.reset
|
33 |
|
34 | global[k] = v for own k, v of require './src/module'
|
35 | global.FIXTURES_DIR = FIXTURES_DIR
|
36 | global.path = path
|
37 | global.escodegen = escodegen
|
38 | global.fs = sfs
|
39 | global.fixtures = (opts) ->
|
40 | do sfs.reset
|
41 | sfs.applySync opts
|
42 |
|
43 | global.bundle = bundle = (entryPoint, opts) ->
|
44 | root = path.resolve FIXTURES_DIR, (opts.root ? '')
|
45 | escodegen.generate cjsify entryPoint, root, opts
|
46 | global.bundleEval = (entryPoint, opts = {}, env = {}) ->
|
47 | global$ = Object.create null
|
48 | global$.module$ = module$ = {}
|
49 | global$[key] = val for own key, val of env
|
50 | opts.export = 'module$.exports'
|
51 | vm.runInNewContext (bundle entryPoint, opts), global$, ''
|
52 | module$.exports
|
53 |
|
54 | extensions = ['.js', '.coffee']
|
55 | relativeResolve = require './src/relative-resolve'
|
56 | global.resolve = (givenPath, cwd = '') ->
|
57 | realCwd = path.resolve path.join FIXTURES_DIR, cwd
|
58 | resolved = relativeResolve {extensions, root: FIXTURES_DIR, cwd: realCwd, path: givenPath}
|
59 | resolved.canonicalName
|