mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
73e7c1c52e
comment Adding test harness Using key strokes in main window test Tests work now Clean up argument variables Rename list manager and get rid of old spec-helper methods Extract out time overrides from spec-helper Spectron test for contenteditable fix spec exit codes and boot mode fix(spec): cleanup N1.sh and make specs fail with exit code 1 Revert tests and get it working in window Move to spec_integration and add window load tester Specs pass. Console logs still in Remove console logs Extract N1 Launcher ready method Make integrated unit test runner feat(tests): adding integration tests Summary: The /spectron folder got moved to /spec_integration There are now unit tests (the old ones) run via the renamed `script/grunt run-unit-tests` There are now integration tests run via the command `script/grunt run-integration-tests`. There are two types of integration tests: 1. Tests that operate on the whole app via Selenium/Chromedriver. These tests have access to Spectron APIs but do NOT have access to any JS object running inside the application. See the `app-boot-spec.es6` for an example of these tests. This is tricky because we want to test the Main window, but Spectron may latch onto any other of our loading windows. Code in `integration-helper` give us an API that finds and loads the main window so we can test it 2. Tests that run in the unit test suite that need Spectron to perform integration-like behavior. These are the contentedtiable specs. The Spectron server is accessed from the app and can be used to trigger actions on the running app, from the app. These tests use the windowed-test runner so Spectron can identify whether the tests have completed, passed, or failed. Unfortunately Spectron can't access the logs , nor the exit code of the test script thereby forcing us to parse the HTML DOM. (Note this is still a WIP) I also revamped the `N1.sh` file when getting the launch arguments to work properly. It's much cleaner. We didn't need most of the data. Test Plan: new tests Reviewers: juan, bengotow Differential Revision: https://phab.nylas.com/D2289 Fix composer specs Tests can properly detect when Spectron is in the environment Report plain text output in specs fixing contenteditable specs Testing slow keymaps on contenteditable specs Move to DOm mutation Spell as `subtree` not `subTree`
83 lines
2.8 KiB
JavaScript
83 lines
2.8 KiB
JavaScript
import path from 'path'
|
|
import Promise from 'bluebird'
|
|
import {Application} from 'spectron';
|
|
|
|
class N1Launcher extends Application {
|
|
constructor(launchArgs = []) {
|
|
super({
|
|
path: N1Launcher.electronPath(),
|
|
args: [jasmine.NYLAS_ROOT_PATH].concat(N1Launcher.defaultNylasArgs()).concat(launchArgs)
|
|
})
|
|
}
|
|
|
|
mainWindowReady() {
|
|
// Wrap in a Bluebird promise so we have `.finally on the return`
|
|
return Promise.resolve(this.start().then(()=>{
|
|
return N1Launcher.waitUntilMainWindowLoaded(this.client).then((mainWindowId)=>{
|
|
return this.client.window(mainWindowId)
|
|
})
|
|
}));
|
|
}
|
|
|
|
static defaultNylasArgs() {
|
|
return ["--enable-logging", `--resource-path=${jasmine.NYLAS_ROOT_PATH}`]
|
|
}
|
|
|
|
static electronPath() {
|
|
nylasRoot = jasmine.NYLAS_ROOT_PATH
|
|
if (process.platform === "darwin") {
|
|
return path.join(nylasRoot, "electron", "Electron.app", "Contents", "MacOS", "Electron")
|
|
} else if (process.platform === "win32") {
|
|
return path.join(nylasRoot, "electron", "electron.exe")
|
|
}
|
|
else if (process.platform === "linux") {
|
|
return path.join(nylasRoot, "electron", "electron")
|
|
}
|
|
else {
|
|
throw new Error(`Platform ${process.platform} is not supported`)
|
|
}
|
|
}
|
|
|
|
// We unfortunatley can't just Spectron's `waitUntilWindowLoaded` because
|
|
// the first window that loads isn't necessarily the main render window (it
|
|
// could be the work window or others), and once the window is "loaded"
|
|
// it'll take a while for packages to load, etc. As such we periodically
|
|
// poll the list of windows to find one that looks like the main loaded
|
|
// window.
|
|
//
|
|
// Returns a promise that resolves with the main window's ID once it's
|
|
// loaded.
|
|
static waitUntilMainWindowLoaded(client, lastCheck=0) {
|
|
var CHECK_EVERY = 1000
|
|
return new Promise((resolve, reject) => {
|
|
client.windowHandles().then(({value}) => {
|
|
return Promise.mapSeries(value, (windowId)=>{
|
|
return N1Launcher.switchAndCheckForMain(client, windowId)
|
|
})
|
|
}).then((mainChecks)=>{
|
|
for (mainWindowId of mainChecks) {
|
|
if (mainWindowId) {return resolve(mainWindowId)}
|
|
}
|
|
|
|
var now = Date.now();
|
|
var delay = Math.max(CHECK_EVERY - (now - lastCheck), 0)
|
|
setTimeout(()=>{
|
|
N1Launcher.waitUntilMainWindowLoaded(client, now).then(resolve)
|
|
}, delay)
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Returns false or the window ID of the main window
|
|
static switchAndCheckForMain(client, windowId) {
|
|
return client.window(windowId).then(()=>{
|
|
return client.isExisting(".main-window-loaded").then((exists)=>{
|
|
if (exists) {return windowId} else {return false}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = {N1Launcher}
|