mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-23 02:28:55 +00:00
a360f6c2ee
This implements the following cases: * Basic runs for a specific version/platform/arch with default options (testing for existence of expected output files/folders) * Runs for each target platform with `out` set * Runs for each target platform with `asar` set * Runs for each target platform with `prune` set * Runs for each target platform with `ignore` set * This includes testing `ignore` including a path separator * This also includes testing that `ignore` entries are applied with the app folder trimmed * Runs for each target platform with `overwrite` set / not set * Runs with `all` set, with `arch` or `platform` each set to `all`, and with `platform` set to multiple platforms (comma-delimited or array) * Tests specifically for the darwin target platform, to test `icon` and `sign` The test logic is organized such that the version of Electron being tested can be configured once centrally (in config.json), and the tests will not run until after downloading any necessary electron versions (to avoid timing out due to long downloads). Resolves #77.
101 lines
2.8 KiB
JavaScript
101 lines
2.8 KiB
JavaScript
var fs = require('fs')
|
|
var path = require('path')
|
|
var test = require('tape')
|
|
|
|
var download = require('electron-download')
|
|
var mkdirp = require('mkdirp')
|
|
var rimraf = require('rimraf')
|
|
var series = require('run-series')
|
|
|
|
var ORIGINAL_CWD = process.cwd()
|
|
var WORK_CWD = path.join(__dirname, 'work')
|
|
|
|
var archs = ['ia32', 'x64']
|
|
var platforms = ['darwin', 'linux', 'win32']
|
|
var slice = Array.prototype.slice
|
|
var version = require('./config.json').version
|
|
|
|
var combinations = []
|
|
archs.forEach(function (arch) {
|
|
platforms.forEach(function (platform) {
|
|
// Electron does not have 32-bit releases for Mac OS X, so skip that combination
|
|
// Also skip testing darwin target on Windows since electron-packager itself skips it
|
|
// (see https://github.com/maxogden/electron-packager/issues/71)
|
|
if (platform === 'darwin' && (arch === 'ia32' || require('os').platform() === 'win32')) return
|
|
|
|
combinations.push({
|
|
arch: arch,
|
|
platform: platform,
|
|
version: version
|
|
})
|
|
})
|
|
})
|
|
|
|
exports.areFilesEqual = function areFilesEqual (file1, file2, callback) {
|
|
series([
|
|
function (cb) {
|
|
fs.readFile(file1, cb)
|
|
},
|
|
function (cb) {
|
|
fs.readFile(file2, cb)
|
|
}
|
|
], function (err, buffers) {
|
|
callback(err, slice.call(buffers[0]).every(function (b, i) {
|
|
return b === buffers[1][i]
|
|
}))
|
|
})
|
|
}
|
|
|
|
exports.downloadAll = function downloadAll (version, callback) {
|
|
series(combinations.map(function (combination) {
|
|
return function (cb) {
|
|
download(combination, cb)
|
|
}
|
|
}), callback)
|
|
}
|
|
|
|
exports.forEachCombination = function forEachCombination (cb) {
|
|
combinations.forEach(cb)
|
|
}
|
|
|
|
exports.generateResourcesPath = function generateResourcesPath (opts) {
|
|
return opts.platform === 'darwin' ? path.join(opts.name + '.app', 'Contents', 'Resources') : 'resources'
|
|
}
|
|
|
|
exports.getWorkCwd = function getWorkCwd () {
|
|
return WORK_CWD
|
|
}
|
|
|
|
// tape doesn't seem to have a provision for before/beforeEach/afterEach/after,
|
|
// so run setup/teardown and cleanup tasks as additional "tests" to put them in sequence
|
|
// and run them irrespective of test failures
|
|
|
|
exports.setup = function setup () {
|
|
test('setup', function (t) {
|
|
mkdirp(WORK_CWD, function (err) {
|
|
if (err) t.end(err)
|
|
process.chdir(WORK_CWD)
|
|
t.end()
|
|
})
|
|
})
|
|
}
|
|
|
|
exports.teardown = function teardown () {
|
|
test('teardown', function (t) {
|
|
process.chdir(ORIGINAL_CWD)
|
|
rimraf(WORK_CWD, function (err) {
|
|
t.end(err)
|
|
})
|
|
})
|
|
}
|
|
|
|
exports.testAllPlatforms = function testAllPlatforms (name, createTest /*, ...createTestArgs */) {
|
|
var args = slice.call(arguments, 2)
|
|
exports.setup()
|
|
exports.forEachCombination(function (combination) {
|
|
test(name + ': ' + combination.platform + '-' + combination.arch,
|
|
createTest.apply(null, [combination].concat(args)))
|
|
})
|
|
exports.teardown()
|
|
}
|