remove unnecessary tests & dependencies from `/npm`
This commit is contained in:
Родитель
1577360312
Коммит
cd1c5103c7
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -3,7 +3,7 @@
|
|||
"cache-clean": "rm -rf ~/.electron && rm -rf dist",
|
||||
"postinstall": "node install.js",
|
||||
"pretest": "npm run cache-clean",
|
||||
"test": "tape test/index.js && standard"
|
||||
"test": "standard"
|
||||
},
|
||||
"bin": {
|
||||
"electron": "cli.js"
|
||||
|
@ -16,13 +16,9 @@
|
|||
"extract-zip": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"adm-zip": "^0.4.7",
|
||||
"home-path": "^0.1.1",
|
||||
"path-exists": "^2.0.0",
|
||||
"proxyquire": "^1.8.0",
|
||||
"sinon": "^2.3.8",
|
||||
"standard": "^5.4.1",
|
||||
"tape": "^3.0.1"
|
||||
"standard": "^5.4.1"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
var fs = require('fs')
|
||||
var tape = require('tape')
|
||||
var path = require('path')
|
||||
var childProcess = require('child_process')
|
||||
|
||||
tape('install fails for unsupported platforms', function (t) {
|
||||
install({npm_config_platform: 'android'}, function (code, stderr) {
|
||||
t.notEqual(stderr.indexOf('Electron builds are not available on platform: android'), -1, 'has error message')
|
||||
t.notEqual(code, 0, 'exited with error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape('install fails for unsupported architectures', function (t) {
|
||||
install({
|
||||
npm_config_arch: 'midcentury',
|
||||
npm_config_platform: 'win32',
|
||||
HOME: process.env.HOME,
|
||||
USERPROFILE: process.env.USERPROFILE
|
||||
}, function (code, stderr) {
|
||||
t.notEqual(stderr.indexOf('Failed to find Electron'), -1, 'has error message')
|
||||
t.notEqual(stderr.indexOf('win32-midcentury'), -1, 'has error message')
|
||||
t.notEqual(code, 0, 'exited with error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape('require fails for corrupted installs', function (t) {
|
||||
cli(function (code, stderr) {
|
||||
t.notEqual(stderr.indexOf('Electron failed to install correctly'), -1, 'has error message')
|
||||
t.notEqual(code, 0, 'exited with error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
function install (env, callback) {
|
||||
var restoreFile = removeFile(path.join(__dirname, '..', 'dist', 'version'))
|
||||
|
||||
var installPath = path.join(__dirname, '..', 'install.js')
|
||||
var installProcess = childProcess.fork(installPath, {
|
||||
silent: true,
|
||||
env: env
|
||||
})
|
||||
|
||||
var stderr = ''
|
||||
installProcess.stderr.on('data', function (data) {
|
||||
stderr += data
|
||||
})
|
||||
|
||||
installProcess.on('close', function (code) {
|
||||
restoreFile()
|
||||
callback(code, stderr)
|
||||
})
|
||||
}
|
||||
|
||||
function cli (callback) {
|
||||
var restoreFile = removeFile(path.join(__dirname, '..', 'path.txt'))
|
||||
|
||||
var cliPath = path.join(__dirname, '..', 'cli.js')
|
||||
var cliProcess = childProcess.fork(cliPath, {
|
||||
silent: true
|
||||
})
|
||||
|
||||
var stderr = ''
|
||||
cliProcess.stderr.on('data', function (data) {
|
||||
stderr += data
|
||||
})
|
||||
|
||||
cliProcess.on('close', function (code) {
|
||||
restoreFile()
|
||||
callback(code, stderr)
|
||||
})
|
||||
}
|
||||
|
||||
function removeFile (filePath) {
|
||||
var contents = null
|
||||
if (fs.existsSync(filePath)) {
|
||||
contents = fs.readFileSync(filePath)
|
||||
fs.unlinkSync(filePath)
|
||||
}
|
||||
return function restoreFile () {
|
||||
if (contents != null) {
|
||||
fs.writeFileSync(filePath, contents)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
const tape = require('tape')
|
||||
const proxyquire = require('proxyquire')
|
||||
const path = require('path')
|
||||
const sinon = require('sinon')
|
||||
const AdmZip = require('adm-zip')
|
||||
const temp = require('temp')
|
||||
|
||||
let sandbox
|
||||
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')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('download electron', (t) => {
|
||||
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()
|
||||
})
|
|
@ -1,15 +0,0 @@
|
|||
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()
|
||||
})
|
Загрузка…
Ссылка в новой задаче