1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | os = require 'os'
|
19 | fs = require 'fs'
|
20 | path = require 'path'
|
21 | exec = require('child_process').exec
|
22 |
|
23 | chai = require 'chai'
|
24 | expect = chai.expect
|
25 | request = require 'request'
|
26 |
|
27 | aspm = require '../lib'
|
28 |
|
29 | platform = os.platform()
|
30 |
|
31 | defaultTargets = '0.17.2 0.19.5 0.20.1'.split ' '
|
32 | defaultArchs = 'ia32 x64'.split ' '
|
33 | defaultArchs = ['ia32'] if platform is 'win32'
|
34 |
|
35 |
|
36 | testModule = (moduleName, opts, cb) ->
|
37 | [moduleName] = moduleName.split '@'
|
38 | quiet = opts.quiet
|
39 | atomShellExe = path.join 'atom-shell', "atom-shell-v#{opts.target}-#{platform}-#{opts.arch}", 'atom'
|
40 | atomShellExe += '.exe' if platform is 'win32'
|
41 | testDir = path.join 'tmp', moduleName
|
42 | cmd = """
|
43 | env ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 #{atomShellExe} -e "require('./tmp/node_modules/#{moduleName}'); console.log('OK: required #{moduleName}')"
|
44 | """
|
45 | errMsg = ''
|
46 | child = exec cmd
|
47 | child.stdout.pipe process.stdout unless quiet
|
48 | unless quiet
|
49 | child.stderr.pipe process.stderr
|
50 | else
|
51 | child.stderr.on 'data', (chunk) -> errMsg += chunk; return
|
52 | child.on 'exit', (code) ->
|
53 | return cb?(new Error "command failed: #{cmd}\n#{errMsg}") if code isnt 0
|
54 | cb?()
|
55 | return
|
56 |
|
57 | testInstallMulti = (moduleName, targets=defaultTargets, archs=defaultArchs, opts={}) ->
|
58 | for target in targets
|
59 | for arch in archs
|
60 | currentOpts = {}
|
61 | currentOpts[key] = val for key, val of opts
|
62 | currentOpts.target = target
|
63 | currentOpts.arch = arch
|
64 |
|
65 | testInstall moduleName, currentOpts
|
66 | return
|
67 |
|
68 | testInstall = (moduleName, opts={}) ->
|
69 | opts.quiet = yes unless '--verbose' in process.argv
|
70 | opts.cwd = 'tmp'
|
71 | msg = moduleName
|
72 | msg += " for Atom-Shell@#{opts.target} on #{platform} #{opts.arch}" if opts.target and opts.arch
|
73 | msg += " from #{opts.tarball}" if opts.tarball
|
74 | it msg, (done) ->
|
75 |
|
76 | aspm.installModule moduleName, opts, (err) ->
|
77 | return done err if err
|
78 | return done err unless opts.target and opts.arch
|
79 | testModule moduleName, opts, (err) ->
|
80 | return done err
|
81 | return
|
82 | return
|
83 | return
|
84 |
|
85 | downloadAtomShellMulti = (targets=defaultTargets, archs=defaultArchs, opts={}) ->
|
86 | for target in targets
|
87 | for arch in archs
|
88 | do (target, arch) ->
|
89 | it "#{target} #{platform} #{arch}", (done) -> downloadAtomShell target, arch, done
|
90 | return
|
91 |
|
92 | downloadAtomShell = (target, arch, cb) ->
|
93 | try fs.mkdirSync 'atom-shell'
|
94 | releaseName = "atom-shell-v#{target}-#{platform}-#{arch}"
|
95 | dir = path.join 'atom-shell', releaseName
|
96 | return cb() if fs.existsSync dir
|
97 | url = "http://github.com/atom/atom-shell/releases/download/v#{target}/#{releaseName}.zip"
|
98 | zipfileName = path.join 'atom-shell', "#{releaseName}.zip"
|
99 | zipfile = fs.createWriteStream zipfileName
|
100 | request(url).pipe(zipfile).on 'finish', ->
|
101 | zipfile.close ->
|
102 | exec "unzip #{zipfileName} -d #{dir}", (err) ->
|
103 | fs.unlink zipfileName, cb
|
104 | return
|
105 | return
|
106 | return
|
107 | return
|
108 |
|
109 |
|
110 | describe 'download atom-shell', ->
|
111 | @timeout 1000*60 * 5
|
112 |
|
113 | downloadAtomShellMulti()
|
114 |
|
115 | describe 'build', ->
|
116 | @timeout 1000*60 * 2
|
117 |
|
118 | try fs.mkdirSync 'tmp'
|
119 |
|
120 | fs.writeFileSync path.join('tmp', 'package.json'), """
|
121 | {
|
122 | "name": "aspm-test",
|
123 | "description": "...",
|
124 | "version": "0.0.1",
|
125 | "private": true
|
126 | }
|
127 | """
|
128 |
|
129 | describe 'js-only module', ->
|
130 | testInstall 'async'
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | describe 'native module', ->
|
137 | testInstallMulti 'time@0.11.0'
|
138 | testInstallMulti 'leveldown@1.0.0'
|
139 | testInstallMulti 'nslog@1.0.1'
|
140 | testInstallMulti 'pathwatcher@2.3.5'
|
141 |
|
142 |
|
143 | describe 'native module /w node-pre-gyp', ->
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | testInstallMulti 'serialport@1.4.9'
|
150 | testInstallMulti 'zipfile@0.5.4'
|
151 | testInstallMulti 'v8-profiler@5.2.1'
|
152 | testInstallMulti 'sqlite3@3.0.4', ['0.17.2']
|
153 | testInstallMulti 'sqlite3@master', ['0.19.5', '0.20.1'], null, tarball: 'https://github.com/mapbox/node-sqlite3/archive/master.tar.gz'
|
154 |
|
155 | describe 'node-pre-gyp test app', ->
|
156 | testInstallMulti 'node-pre-gyp-test-app1', null, null, tarball: '../test/node-pre-gyp/app1.tar.gz'
|
157 | testInstallMulti 'node-pre-gyp-test-app3', null, null, tarball: '../test/node-pre-gyp/app3.tar.gz'
|