add tests for npm install
This commit is contained in:
parent
663710e8eb
commit
40555371ba
3 changed files with 106 additions and 11 deletions
|
@ -2,8 +2,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"cache-clean": "rm -rf ~/.electron && rm -rf dist",
|
"cache-clean": "rm -rf ~/.electron && rm -rf dist",
|
||||||
"postinstall": "node install.js",
|
"postinstall": "node install.js",
|
||||||
"pretest": "npm run cache-clean && npm run postinstall",
|
"pretest": "npm run cache-clean",
|
||||||
"test": "tape test/*.js && standard"
|
"test": "tape test/index.js && standard"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"electron": "cli.js"
|
"electron": "cli.js"
|
||||||
|
@ -16,8 +16,11 @@
|
||||||
"extract-zip": "^1.0.3"
|
"extract-zip": "^1.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"adm-zip": "^0.4.7",
|
||||||
"home-path": "^0.1.1",
|
"home-path": "^0.1.1",
|
||||||
"path-exists": "^2.0.0",
|
"path-exists": "^2.0.0",
|
||||||
|
"proxyquire": "^1.8.0",
|
||||||
|
"sinon": "^2.3.8",
|
||||||
"standard": "^5.4.1",
|
"standard": "^5.4.1",
|
||||||
"tape": "^3.0.1"
|
"tape": "^3.0.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,15 +1,92 @@
|
||||||
var tape = require('tape')
|
const tape = require('tape')
|
||||||
var electron = require('../')
|
const proxyquire = require('proxyquire')
|
||||||
var path = require('path')
|
const path = require('path')
|
||||||
var pathExists = require('path-exists')
|
const sinon = require('sinon')
|
||||||
var getHomePath = require('home-path')()
|
const admZip = require('adm-zip')
|
||||||
|
const temp = require('temp')
|
||||||
|
// var pathExists = require('path-exists')
|
||||||
|
// var getHomePath = require('home-path')()
|
||||||
|
|
||||||
tape('has local binary', function (t) {
|
let sandbox
|
||||||
t.ok(pathExists.sync(electron), 'electron was downloaded')
|
const mockEnv = {
|
||||||
|
electron_config_cache: 'cache',
|
||||||
|
npm_config_platform: 'linux',
|
||||||
|
npm_config_arch: 'win32',
|
||||||
|
npm_config_strict_ssl: 'true',
|
||||||
|
force_no_cache: 'false',
|
||||||
|
npm_config_loglevel: 'silly'
|
||||||
|
}
|
||||||
|
let tempDir
|
||||||
|
temp.track()
|
||||||
|
|
||||||
|
tape('set up', (t) => {
|
||||||
|
sandbox = sinon.sandbox.create()
|
||||||
|
tempDir = temp.mkdirSync('electron-install')
|
||||||
|
console.log(tempDir)
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
tape('has cache folder', function (t) {
|
tape('download electron', (t) => {
|
||||||
t.ok(pathExists.sync(path.join(getHomePath, './.electron')), 'cache exists')
|
const downloadSpy = sinon.spy()
|
||||||
|
|
||||||
|
sandbox.stub(process, 'env').value(mockEnv)
|
||||||
|
proxyquire(path.join(__dirname, '..', 'install.js'), {
|
||||||
|
'electron-download': downloadSpy
|
||||||
|
})
|
||||||
|
t.ok(downloadSpy.calledWith({
|
||||||
|
cache: mockEnv.electron_config_cache,
|
||||||
|
version: require('../../package').version.replace(/-.*/, ''),
|
||||||
|
platform: mockEnv.npm_config_platform,
|
||||||
|
arch: mockEnv.npm_config_arch,
|
||||||
|
strictSSL: mockEnv.npm_config_strict_ssl === 'true',
|
||||||
|
force: mockEnv.force_no_cache === 'true',
|
||||||
|
quiet: false
|
||||||
|
}), 'electron-download is called with correct options')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('fails for unsupported platforms', (t) => {
|
||||||
|
sandbox.restore()
|
||||||
|
sandbox.stub(process, 'env').value(
|
||||||
|
Object.assign(mockEnv, { npm_config_platform: 'android' })
|
||||||
|
)
|
||||||
|
t.throws(() => {
|
||||||
|
proxyquire(path.join(__dirname, '..', 'install.js'), {
|
||||||
|
'electron-download': sinon.spy()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/Electron builds are not available on platform: android/i,
|
||||||
|
'install fails for unsupported platforms')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('extract file', (t) => {
|
||||||
|
|
||||||
|
sandbox.restore()
|
||||||
|
|
||||||
|
sandbox.stub(process, 'env').value(
|
||||||
|
Object.assign(mockEnv, { npm_config_platform: 'darwin' })
|
||||||
|
)
|
||||||
|
|
||||||
|
// add file directly
|
||||||
|
const zip = new admZip()
|
||||||
|
zip.addFile('test.txt', Buffer.from('electron install test'))
|
||||||
|
zip.writeZip(path.join(tempDir, 'test.zip'))
|
||||||
|
|
||||||
|
// create fake zip
|
||||||
|
// mock download() returning path to fake zip
|
||||||
|
|
||||||
|
proxyquire(path.join(__dirname, '..', 'install.js'), {
|
||||||
|
'electron-download': (opts, cb) => cb(null, path.join(tempDir, 'test.zip'))
|
||||||
|
})
|
||||||
|
|
||||||
|
// call through to extractFile()
|
||||||
|
// check `/path.txt` to contain platformPath
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('teardown', (t) => {
|
||||||
|
// remove files
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
15
npm/test/test.js
Normal file
15
npm/test/test.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
var tape = require('tape')
|
||||||
|
var electron = require('../')
|
||||||
|
var path = require('path')
|
||||||
|
var pathExists = require('path-exists')
|
||||||
|
var getHomePath = require('home-path')()
|
||||||
|
|
||||||
|
tape('has local binary', function (t) {
|
||||||
|
t.ok(pathExists.sync(electron), 'electron was downloaded')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('has cache folder', function (t) {
|
||||||
|
t.ok(pathExists.sync(path.join(getHomePath, './.electron')), 'cache exists')
|
||||||
|
t.end()
|
||||||
|
})
|
Loading…
Reference in a new issue