Fix flaky test-release test
This commit is contained in:
parent
0a90380ac8
commit
e5111c4565
3 changed files with 7 additions and 3 deletions
55
ts/scripts/test-electron.ts
Normal file
55
ts/scripts/test-electron.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import { execFileSync } from 'child_process';
|
||||
import { join } from 'path';
|
||||
|
||||
const ROOT_DIR = join(__dirname, '..', '..');
|
||||
|
||||
const ELECTRON = join(
|
||||
ROOT_DIR,
|
||||
'node_modules',
|
||||
'.bin',
|
||||
process.platform === 'win32' ? 'electron.cmd' : 'electron'
|
||||
);
|
||||
|
||||
const stdout = execFileSync(ELECTRON, [ROOT_DIR], {
|
||||
cwd: ROOT_DIR,
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_ENV: 'test',
|
||||
TEST_QUIT_ON_COMPLETE: 'on',
|
||||
},
|
||||
encoding: 'utf8',
|
||||
});
|
||||
|
||||
const match = stdout.match(/ci:test-electron:done=(.*)?\n/);
|
||||
|
||||
if (!match) {
|
||||
throw new Error('No test results were found in stdout');
|
||||
}
|
||||
|
||||
const {
|
||||
passed,
|
||||
failed,
|
||||
}: {
|
||||
passed: Array<string>;
|
||||
failed: Array<{ testName: string; error: string }>;
|
||||
} = JSON.parse(match[1]);
|
||||
|
||||
const total = passed.length + failed.length;
|
||||
|
||||
for (const { testName, error } of failed) {
|
||||
console.error(`- ${testName}`);
|
||||
console.error(error);
|
||||
console.error('');
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Passed ${passed.length} | Failed ${failed.length} | Total ${total}`
|
||||
);
|
||||
|
||||
if (failed.length !== 0) {
|
||||
process.exit(1);
|
||||
}
|
84
ts/scripts/test-release.ts
Normal file
84
ts/scripts/test-release.ts
Normal file
|
@ -0,0 +1,84 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import asar from 'asar';
|
||||
import assert from 'assert';
|
||||
import { join } from 'path';
|
||||
import { _electron as electron } from 'playwright';
|
||||
|
||||
import packageJson from '../../package.json';
|
||||
|
||||
const ENVIRONMENT = 'production';
|
||||
const RELEASE_DIR = join(__dirname, '..', '..', 'release');
|
||||
|
||||
let archive: string;
|
||||
let exe: string;
|
||||
if (process.platform === 'darwin') {
|
||||
archive = join(
|
||||
'mac',
|
||||
`${packageJson.productName}.app`,
|
||||
'Contents',
|
||||
'Resources',
|
||||
'app.asar'
|
||||
);
|
||||
exe = join(
|
||||
'mac',
|
||||
`${packageJson.productName}.app`,
|
||||
'Contents',
|
||||
'MacOS',
|
||||
packageJson.productName
|
||||
);
|
||||
} else if (process.platform === 'win32') {
|
||||
archive = join('win-unpacked', 'resources', 'app.asar');
|
||||
exe = join('win-unpacked', `${packageJson.productName}.exe`);
|
||||
} else if (process.platform === 'linux') {
|
||||
archive = join('linux-unpacked', 'resources', 'app.asar');
|
||||
exe = join('linux-unpacked', packageJson.name);
|
||||
} else {
|
||||
throw new Error(`Unsupported platform: ${process.platform}`);
|
||||
}
|
||||
|
||||
const files = [
|
||||
join('config', 'default.json'),
|
||||
join('config', `${ENVIRONMENT}.json`),
|
||||
join('config', `local-${ENVIRONMENT}.json`),
|
||||
];
|
||||
|
||||
for (const fileName of files) {
|
||||
console.log(`Checking that ${fileName} exists in asar ${archive}`);
|
||||
try {
|
||||
asar.statFile(join(RELEASE_DIR, archive), fileName);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
throw new Error(`Missing file ${fileName}`);
|
||||
}
|
||||
}
|
||||
|
||||
// A simple test to verify a visible window is opened with a title
|
||||
const main = async () => {
|
||||
const executablePath = join(RELEASE_DIR, exe);
|
||||
console.log('Starting path', executablePath);
|
||||
const app = await electron.launch({
|
||||
executablePath,
|
||||
locale: 'en',
|
||||
});
|
||||
|
||||
console.log('Waiting for a first window');
|
||||
const window = await app.firstWindow();
|
||||
|
||||
console.log('Waiting for app to fully load');
|
||||
await window.waitForSelector(
|
||||
'.App, .app-loading-screen:has-text("Optimizing")'
|
||||
);
|
||||
|
||||
console.log('Checking window title');
|
||||
assert.strictEqual(await window.title(), packageJson.productName);
|
||||
|
||||
await app.close();
|
||||
};
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue