Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #781 from malept/use-ava
Use AVA instead of tape
- Loading branch information
Showing
21 changed files
with
1,178 additions
and
1,489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*.key | ||
*.pem | ||
node_modules | ||
test/fixtures/basic/main-link.js | ||
test/work | ||
.DS_Store | ||
.nyc_output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict' | ||
|
||
const common = require('../common') | ||
const config = require('./config.json') | ||
const exec = require('mz/child_process').exec | ||
const fs = require('fs-extra') | ||
const os = require('os') | ||
const path = require('path') | ||
const targets = require('../targets') | ||
|
||
function fixtureSubdir (subdir) { | ||
return path.join(__dirname, 'fixtures', subdir) | ||
} | ||
|
||
function downloadAll (version) { | ||
console.log(`Calling electron-download for ${version} before running tests...`) | ||
const combinations = common.createDownloadCombos({electronVersion: config.version, all: true}, targets.officialPlatforms, targets.officialArchs, (platform, arch) => { | ||
// Skip testing darwin/mas target on Windows since electron-packager itself skips it | ||
// (see https://github.com/electron-userland/electron-packager/issues/71) | ||
return common.isPlatformMac(platform) && process.platform === 'win32' | ||
}) | ||
|
||
return Promise.all(combinations.map(combination => { | ||
return common.downloadElectronZip(Object.assign({}, combination, { | ||
cache: path.join(os.homedir(), '.electron'), | ||
quiet: !!process.env.CI, | ||
version: version | ||
})) | ||
})) | ||
} | ||
|
||
// Download all Electron distributions before running tests to avoid timing out due to network | ||
// speed. Most tests run with the config.json version, but we have some tests using 0.37.4, and an | ||
// electron module specific test using 1.3.1. | ||
function preDownloadElectron () { | ||
const versions = [ | ||
config.version, | ||
'0.37.4', | ||
'1.3.1' | ||
] | ||
return Promise.all(versions.map(downloadAll)) | ||
} | ||
|
||
function npmInstallForFixture (fixture) { | ||
const fixtureDir = fixtureSubdir(fixture) | ||
return fs.exists(path.join(fixtureDir, 'node_modules')) | ||
.then(exists => { | ||
if (exists) { | ||
return true | ||
} else { | ||
console.log(`Running npm install in fixtures/${fixture}...`) | ||
return exec('npm install --no-bin-links', {cwd: fixtureDir}) | ||
} | ||
}) | ||
} | ||
|
||
function npmInstallForFixtures () { | ||
const fixtures = [ | ||
'basic', | ||
'basic-renamed-to-electron', | ||
'infer-missing-version-only', | ||
'el-0374' | ||
] | ||
return Promise.all(fixtures.map(npmInstallForFixture)) | ||
} | ||
|
||
const WORK_CWD = path.join(__dirname, 'work') | ||
|
||
function ensureEmptyWorkDirExists () { | ||
return fs.remove(WORK_CWD) | ||
.then(() => fs.mkdirs(WORK_CWD)) | ||
} | ||
|
||
module.exports = { | ||
fixtureSubdir: fixtureSubdir, | ||
setupTestsuite: function setupTestsuite () { | ||
return preDownloadElectron() | ||
.then(npmInstallForFixtures) | ||
.catch(error => { | ||
console.error(error.stack || error) | ||
return process.exit(1) | ||
}) | ||
.then(ensureEmptyWorkDirExists) | ||
}, | ||
WORK_CWD: WORK_CWD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
'use strict' | ||
|
||
// Keeping this module because it handles non-buffers gracefully | ||
const bufferEqual = require('buffer-equal') | ||
const common = require('../common') | ||
const config = require('./config.json') | ||
const fs = require('fs-extra') | ||
const packager = require('../index') | ||
const path = require('path') | ||
const setup = require('./_setup') | ||
const tempy = require('tempy') | ||
const test = require('ava') | ||
|
||
const ORIGINAL_CWD = process.cwd() | ||
|
||
test.before(t => { | ||
if (!process.env.CI) { | ||
return setup.setupTestsuite() | ||
.then(() => process.chdir(setup.WORK_CWD)) | ||
} | ||
return Promise.resolve(process.chdir(setup.WORK_CWD)) | ||
}) | ||
|
||
test.after.always(t => { | ||
process.chdir(ORIGINAL_CWD) | ||
return fs.remove(setup.WORK_CWD) | ||
}) | ||
|
||
test.beforeEach(t => { | ||
t.context.workDir = tempy.directory() | ||
t.context.tempDir = tempy.directory() | ||
}) | ||
|
||
test.afterEach.always(t => { | ||
return fs.remove(t.context.workDir) | ||
.then(() => fs.remove(t.context.tempDir)) | ||
}) | ||
|
||
function testSinglePlatform (name, testFunction, testFunctionArgs, parallel) { | ||
module.exports.packagerTest(name, (t, opts) => { | ||
Object.assign(opts, module.exports.singlePlatformOptions()) | ||
return testFunction.apply(null, [t, opts].concat(testFunctionArgs)) | ||
}, parallel) | ||
} | ||
|
||
module.exports = { | ||
allPlatformArchCombosCount: 8, | ||
areFilesEqual: function areFilesEqual (file1, file2) { | ||
let buffer1, buffer2 | ||
|
||
return fs.readFile(file1) | ||
.then((data) => { | ||
buffer1 = data | ||
return fs.readFile(file2) | ||
}).then((data) => { | ||
buffer2 = data | ||
return bufferEqual(buffer1, buffer2) | ||
}) | ||
}, | ||
fixtureSubdir: setup.fixtureSubdir, | ||
generateResourcesPath: function generateResourcesPath (opts) { | ||
return common.isPlatformMac(opts.platform) | ||
? path.join(opts.name + '.app', 'Contents', 'Resources') | ||
: 'resources' | ||
}, | ||
invalidOptionTest: function invalidOptionTest (opts) { | ||
return t => t.throws(packager(opts)) | ||
}, | ||
packageAndEnsureResourcesPath: function packageAndEnsureResourcesPath (t, opts) { | ||
let resourcesPath | ||
|
||
return packager(opts) | ||
.then(paths => { | ||
resourcesPath = path.join(paths[0], module.exports.generateResourcesPath(opts)) | ||
return fs.stat(resourcesPath) | ||
}).then(stats => { | ||
t.true(stats.isDirectory(), 'The output directory should contain the expected resources subdirectory') | ||
return resourcesPath | ||
}) | ||
}, | ||
packagerTest: function packagerTest (name, testFunction, parallel) { | ||
const testDefinition = parallel ? test : test.serial | ||
testDefinition(name, t => { | ||
return testFunction(t, { | ||
name: 'packagerTest', | ||
out: t.context.workDir, | ||
tmpdir: t.context.tempDir | ||
}) | ||
}) | ||
}, | ||
singlePlatformOptions: function singlePlatformOptions () { | ||
return { | ||
platform: 'linux', | ||
arch: 'x64', | ||
electronVersion: config.version | ||
} | ||
}, | ||
// Rest parameters are added (not behind a feature flag) in Node 6 | ||
testSinglePlatform: function (name, testFunction /*, ...testFunctionArgs */) { | ||
const testFunctionArgs = Array.prototype.slice.call(arguments, 2) | ||
return testSinglePlatform(name, testFunction, testFunctionArgs, false) | ||
}, | ||
// Rest parameters are added (not behind a feature flag) in Node 6 | ||
testSinglePlatformParallel: function (name, testFunction /*, ...testFunctionArgs */) { | ||
const testFunctionArgs = Array.prototype.slice.call(arguments, 2) | ||
return testSinglePlatform(name, testFunction, testFunctionArgs, true) | ||
}, | ||
verifyPackageExistence: function verifyPackageExistence (finalPaths) { | ||
return Promise.all(finalPaths.map((finalPath) => { | ||
return fs.stat(finalPath) | ||
.then( | ||
stats => stats.isDirectory(), | ||
() => false | ||
) | ||
})) | ||
} | ||
} |
Oops, something went wrong.