Skip to content

Commit

Permalink
test: migrate to Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 18, 2016
1 parent 1057499 commit 171ad14
Show file tree
Hide file tree
Showing 29 changed files with 1,081 additions and 1,540 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This includes:
- log of the terminal output
- node version
- npm version
- on which system do you want to create installers (MacOS, Windows or Linux)
- on which system do you want to create installers (macOS, Windows or Linux)

# Pull Requests
To check that your contributions match the project coding style make sure `npm test` passes.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# electron-builder [![npm version](https://img.shields.io/npm/v/electron-builder.svg)](https://npmjs.org/package/electron-builder) [![donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W6V79R2RGCCHL)
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box.
A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out of the box.

* NPM packages management:
* [Native application dependencies](http://electron.atom.io/docs/latest/tutorial/using-native-node-modules/) compilation.
Expand All @@ -9,7 +9,7 @@ A complete solution to package and build a ready for distribution Electron app f
* [Build version management](https://github.com/electron-userland/electron-builder/wiki/Options#build-version-management).
* Numerous target formats:
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir` (unpacked directory).
* [MacOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `pkg`, `mas`.
* [macOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `pkg`, `mas`.
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, Squirrel.Windows.
* [Two package.json Structure](https://github.com/electron-userland/electron-builder/wiki/Two-package.json-Structure) is supported, but you are not forced to use it even if you have native production dependencies.
Expand Down
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
"devDependencies": {
"@develar/semantic-release": "^6.3.21",
"@types/ini": "^1.3.29",
"@types/jest": "^16.0.0",
"@types/js-yaml": "^3.5.28",
"@types/source-map-support": "^0.2.28",
"ava-tf": "^0.16.4",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
"babel-plugin-transform-es2015-destructuring": "^6.18.0",
Expand All @@ -111,6 +111,7 @@
"depcheck": "^0.6.4",
"diff": "^3.0.1",
"husky": "^0.11.9",
"jest-cli": "^17.0.3",
"json8": "^0.9.2",
"path-sort": "^0.1.0",
"ts-babel": "^1.1.4",
Expand Down Expand Up @@ -149,6 +150,20 @@
"test/out/*.js"
]
},
"jest": {
"testEnvironment": "node",
"testPathDirs": [
"test/out"
],
"testPathIgnorePatterns": [
"/helpers/"
],
"testRegex": "\\.js$",
"modulePaths": [
"<rootDir>"
],
"setupTestFrameworkScriptFile": "test/jestSetup.js"
},
"release": {
"verifyConditions": []
},
Expand Down
4 changes: 2 additions & 2 deletions src/cliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const deprecated = "Deprecated:"
export function createYargs(): any {
//noinspection ReservedWordAsName
return yargs
.example("build -mwl", "build for MacOS, Windows and Linux")
.example("build -mwl", "build for macOS, Windows and Linux")
.example("build --linux deb tar.xz", "build deb and tar.xz for Linux")
.example("build --win --ia32", "build for Windows ia32")
.example("build --em.foo=bar", "set application package.json property `foo` to `bar`")
.option("mac", {
group: buildGroup,
alias: ["m", "o", "macos"],
describe: `Build for MacOS, accepts target list (see ${underline("https://goo.gl/HAnnq8")}).`,
describe: `Build for macOS, accepts target list (see ${underline("https://goo.gl/HAnnq8")}).`,
type: "array",
})
.option("linux", {
Expand Down
2 changes: 1 addition & 1 deletion src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Packager implements BuildInfo {
let checkWine = this.options.platformPackagerFactory == null
for (let [platform, archToType] of this.options.targets!) {
if (platform === Platform.MAC && process.platform === Platform.WINDOWS.nodeName) {
throw new Error("Build for MacOS is supported only on MacOS, please see https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build")
throw new Error("Build for macOS is supported only on macOS, please see https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build")
}

let wineCheck: Promise<string> | null = null
Expand Down
22 changes: 12 additions & 10 deletions src/publish/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Asset {

export class GitHubPublisher extends Publisher {
private tag: string
private _releasePromise: BluebirdPromise<Release>
private _releasePromise: Promise<Release>

private readonly token: string
private readonly policy: PublishPolicy
Expand Down Expand Up @@ -54,7 +54,7 @@ export class GitHubPublisher extends Publisher {
}

this.tag = info.vPrefixedTagName === false ? version : `v${version}`
this._releasePromise = this.token === "__test__" ? BluebirdPromise.resolve(<any>null) : <BluebirdPromise<Release>>this.init()
this._releasePromise = this.token === "__test__" ? BluebirdPromise.resolve(<any>null) : this.init()
}

private async init(): Promise<Release | null> {
Expand Down Expand Up @@ -153,16 +153,12 @@ export class GitHubPublisher extends Publisher {
// test only
//noinspection JSUnusedGlobalSymbols
async getRelease(): Promise<any> {
return githubRequest<Release>(`/repos/${this.info.owner}/${this.info.repo}/releases/${this._releasePromise.value().id}`, this.token)
return githubRequest<Release>(`/repos/${this.info.owner}/${this.info.repo}/releases/${(await this._releasePromise).id}`, this.token)
}

//noinspection JSUnusedGlobalSymbols
async deleteRelease(): Promise<any> {
if (!this._releasePromise.isFulfilled()) {
return
}

const release = this._releasePromise.value()
const release = await this._releasePromise
if (release == null) {
return
}
Expand All @@ -172,8 +168,14 @@ export class GitHubPublisher extends Publisher {
return await githubRequest(`/repos/${this.info.owner}/${this.info.repo}/releases/${release.id}`, this.token, null, "DELETE")
}
catch (e) {
if (e instanceof HttpError && (e.response.statusCode === 405 || e.response.statusCode === 502)) {
continue
if (e instanceof HttpError) {
if (e.response.statusCode === 404) {
warn(`Cannot delete release ${release.id} — doesn't exist`)
return
}
else if (e.response.statusCode === 405 || e.response.statusCode === 502) {
continue
}
}

throw e
Expand Down
9 changes: 7 additions & 2 deletions src/util/tmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { warn } from "./log"

const mkdtemp: any | null = require("fs-extra-p").mkdtemp

process.setMaxListeners(20)

export class TmpDir {
private tmpFileCounter = 0
private tempDirectoryPromise: BluebirdPromise<string>
Expand All @@ -27,7 +29,7 @@ export class TmpDir {
this.tempDirectoryPromise = promise
.then(dir => {
this.dir = dir
process.on("SIGINT", () => {
const cleanup = () => {
if (this.dir == null) {
return
}
Expand All @@ -41,7 +43,10 @@ export class TmpDir {
warn(`Cannot delete temporary dir "${dir}": ${(e.stack || e).toString()}`)
}
}
})
}
process.on("exit", cleanup)
process.on("uncaughtException", cleanup)
process.on("SIGINT", cleanup)
return dir
})
}
Expand Down
11 changes: 6 additions & 5 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface FileCodeSigningInfo {
export class WinPackager extends PlatformPackager<WinBuildOptions> {
readonly cscInfo: Promise<FileCodeSigningInfo | null> | null

private readonly iconPath: Promise<string>
private iconPath: Promise<string> | null

constructor(info: BuildInfo) {
super(info)
Expand Down Expand Up @@ -59,8 +59,6 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
subjectName: subjectName
})
}

this.iconPath = this.getValidIconPath()
}

protected doGetCscPassword(): string {
Expand Down Expand Up @@ -95,8 +93,11 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
return Platform.WINDOWS
}

async getIconPath() {
return await this.iconPath
getIconPath() {
if (this.iconPath == null) {
this.iconPath = this.getValidIconPath()
}
return this.iconPath
}

private async getValidIconPath(): Promise<string | null> {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"appId": "org.electron-builder.testApp",
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",
"compression": "store",
"npmRebuild": false,
"mac": {
"category": "your.app.category.type"
},
Expand Down
34 changes: 34 additions & 0 deletions test/jestSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict"

require('source-map-support').install()

const isWindows = process.platform === "win32"
const isCi = (process.env.CI || "").toLowerCase() === "true"

// Squirrel.Windows msi is very slow
jasmine.DEFAULT_TIMEOUT_INTERVAL = (isWindows ? 10 : 10) * 1000 * 60

if (!isWindows || isCi) {
//noinspection JSUnresolvedVariable
it = it.concurrent
//noinspection JSUnresolvedVariable
test = it
}

test.ifMac = process.platform === "darwin" ? test : test.skip
test.ifNotWindows = isWindows ? test.skip : test

if (isCi) {
test.ifCi = test
test.ifNotCi = test.skip
}
else {
test.ifCi = test.skip
test.ifNotCi = test
}

test.ifNotCiMac = isCi && process.platform === "darwin" ? test.skip : test

test.ifDevOrWinCi = !isCi || isWindows ? test : test.skip
test.ifDevOrLinuxCi = !isCi || process.platform === "linux" ? test : test.skip
test.ifWinCi = isCi && isWindows ? test : test.skip
9 changes: 7 additions & 2 deletions test/src/ArtifactPublisherTest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import test from "./helpers/avaEx"
import { GitHubPublisher } from "out/publish/gitHubPublisher"
import { HttpError } from "out/publish/restApiRequest"
import { join } from "path"
import { assertThat } from "./helpers/fileAssert"
import { BintrayPublisher } from "out/publish/BintrayPublisher"
import { createPublisher } from "out/builder"

if (process.env.CI && process.platform === "win32") {
fit("Skip ArtifactPublisherTest suite on Windows CI", () => {
console.warn("[SKIP] Skip ArtifactPublisherTest suite on Windows CI")
})
}

function getRandomInt(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min
}
Expand Down Expand Up @@ -103,7 +108,7 @@ testAndIgnoreApiRate("GitHub upload org", async () => {
}
})

test("create publisher", async () => {
it("create publisher", async () => {
const packager: any = {
metadata: {
version: "2.0.0",
Expand Down
Loading

0 comments on commit 171ad14

Please sign in to comment.