Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Automation: Install tests (companion to #2372) (#2378)
Browse files Browse the repository at this point in the history
* Gate tests to only run on Windows

* Fix lint issues

* Hook up setup tests to run as part of 'yarn run test'

* Run setup tests on appveyor; don't run as part of 'yarn run test'

* Uncomment out test that registry key is removed, since Ryan's changes now address that!

* Fix lint issues

* Increase timeout

* Include arch for setup file path

* Include arch for setup file

* Fix up arch on appveyor

* Fix lint issues
  • Loading branch information
bryphe committed Jul 10, 2018
1 parent 75ab1b8 commit 7b5ed4f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 9 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -34,7 +34,7 @@ install:
- npm --version
# install modules
- yarn install
- npm run check-cached-binaries
- yarn run check-cached-binaries

artifacts:
- path: dist/*.exe
Expand Down
15 changes: 8 additions & 7 deletions build/script/appveyor-test.ps1
Expand Up @@ -12,25 +12,26 @@ Write-Host "Platform: " $env:PLATFORM
Write-Host "AppVeyor: " $env:APPVEYOR

# Build
npm run build ; exitIfFailed
npm run lint ; exitIfFailed
npm run test:unit ; exitIfFailed
yarn run build ; exitIfFailed
yarn run lint ; exitIfFailed
yarn run test:unit ; exitIfFailed

# Create setup package
npm run copy-icons ; exitIfFailed
yarn run copy-icons ; exitIfFailed

$platform = (Get-Item env:PLATFORM).value

if ($platform -eq "x86") {
npm run dist:win:x86
yarn run dist:win:x86
} else {
npm run dist:win:x64
yarn run dist:win:x64
}

npm run pack:win ; exitIfFailed
yarn run pack:win ; exitIfFailed

# Run integration tests
npm run test:integration ; exitIfFailed
npm run test:setup ; exitIfFailed

# Build up demo screenshot for commits that aren't PRs.
$prNumber = (Get-Item env:APPVEYOR_PULL_REQUEST_NUMBER).value
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -805,7 +805,8 @@
"dist:win:x64": "cross-env ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=1 build --arch x64 --publish never",
"pack:win": "node build/BuildSetupTemplate.js && innosetup-compiler dist/setup.iss --verbose --O=dist",
"test": "yarn run test:unit && yarn run test:integration",
"test:integration": "yarn run build:test && mocha -t 120000 lib_test/test/CiTests.js --bail",
"test:setup": "yarn run build:test:integration && mocha -t 120000 --recursive lib_test/test/setup",
"test:integration": "yarn run build:test:integration && mocha -t 120000 lib_test/test/CiTests.js --bail",
"test:react": "jest --config ./jest.config.js ./ui-tests",
"test:react:watch": "jest --config ./jest.config.js ./ui-tests --watch",
"test:react:coverage": "jest --config ./jest.config.js ./ui-tests --coverage",
Expand Down
100 changes: 100 additions & 0 deletions test/setup/WindowsInstallerTests.ts
@@ -0,0 +1,100 @@
/**
* WindowsInstallerTests
*/

import * as assert from "assert"
import * as cp from "child_process"
import * as fs from "fs"
import * as os from "os"
import * as path from "path"

const rootPath = path.join(__dirname, "..", "..", "..")
const packageJsonPath = path.join(rootPath, "package.json")
const oniVersion = require(packageJsonPath).version // tslint:disable-line

let arch = os.arch() === "x32" ? "-ia32" : ""

if (process.env.APPVEYOR) {
arch = process.env.PLATFORM === "x86" ? "-ia32" : ""
}

const installExecutablePath = path.join(rootPath, "dist", `Oni-${oniVersion}${arch}-win.exe`)

const runInstaller = (setupExecutablePath: string, installDirectory: string) => {
const doesInstallerExist = fs.existsSync(setupExecutablePath)

assert.strictEqual(
doesInstallerExist,
true,
"Validate installer exists at: " + setupExecutablePath,
)

return cp.spawnSync(installExecutablePath, [
"/silent",
"/norestart",
`/dir=${installDirectory}`,
])
}

const runUninstaller = (uninstallerExecutablePath: string) => {
return cp.spawnSync(uninstallerExecutablePath, ["/silent", "/norestart"])
}

const getPathRegistryKey = () => {
// Use the `reg` command line tool to get information about the registry key
// Use `reg /?` or `reg query /?` at the command line ot get more info

const result = cp.spawnSync("reg", ["query", "HKCU\\Environment", "/e", "/f", "PATH"])

const output = result.output.toString()

// the output is multi-line, so we'll split it up
const [, , lastLine] = output.split("\r\n")

return lastLine.substring(29, lastLine.length)
}

const log = msg => console.log(msg) // tslint:disable-line

if (os.platform() === "win32") {
describe("WindowsInstallerTests", () => {
it("installs / uninstalls to a test directory", () => {
const testDirectory = "oni-test-install-" + new Date().getTime()
const testPath = path.join("C:", testDirectory)

log("Installing to: " + testPath)
const result = runInstaller(installExecutablePath, testPath)

const doesInstallFolderExist = fs.existsSync(testPath)
assert.strictEqual(doesInstallFolderExist, true, "Validate install folder exists now")

const doesOniExeExists = fs.existsSync(path.join(testPath, "Oni.exe"))
assert.strictEqual(doesOniExeExists, true, "Validate Oni.exe exists")

const uninstallExecutablePath = path.join(testPath, "unins000.exe")
const doesUninstallExist = fs.existsSync(uninstallExecutablePath)
assert.strictEqual(doesUninstallExist, true, "Validate uninstaller exists")

const pathKey = getPathRegistryKey()
assert.ok(
pathKey.indexOf(testDirectory) >= 0,
"Validate path was added to registry key",
)

log("Running uninstaller...")
const uninstallResult = runUninstaller(uninstallExecutablePath)

assert.strictEqual(
doesInstallFolderExist,
true,
"Validate install folder doesn't exist after uninstall",
)

const pathKey2 = getPathRegistryKey()
assert.ok(
pathKey2.indexOf(testDirectory) === -1,
"Validate path was removed from registry after installation",
)
})
})
}

0 comments on commit 7b5ed4f

Please sign in to comment.