summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-04-05 14:59:02 +0200
committerOskar Nyberg <oskar@mullvad.net>2023-04-05 14:59:02 +0200
commitb04dc2e451e093618af5c9d89a3852897c2d243f (patch)
treea29a5ab3bc416e6590954926fbd08660d998f23e
parent0021d2618f845299a93a5c2e0bf9019746ccda91 (diff)
parent8df5baa67e530da50a35b39e7c8d89375a76efdb (diff)
downloadmullvadvpn-b04dc2e451e093618af5c9d89a3852897c2d243f.tar.xz
mullvadvpn-b04dc2e451e093618af5c9d89a3852897c2d243f.zip
Merge branch 'fix-windows-tests'
-rw-r--r--gui/standalone-tests.ts66
-rw-r--r--gui/test/e2e/installed/playwright.config.ts10
-rw-r--r--gui/test/e2e/installed/state-dependent/login.spec.ts10
3 files changed, 47 insertions, 39 deletions
diff --git a/gui/standalone-tests.ts b/gui/standalone-tests.ts
index d7aae0a415..c2572311d4 100644
--- a/gui/standalone-tests.ts
+++ b/gui/standalone-tests.ts
@@ -1,4 +1,4 @@
-import { spawnSync, SpawnSyncReturns } from 'child_process';
+import { spawn } from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
@@ -8,27 +8,21 @@ import path from 'path';
// assets and performs the tests. More info in /gui/README.md.
const tmpDir = path.join(os.tmpdir(), 'mullvad-standalone-tests');
-const rootDir = path.join(__dirname, '..');
-const nodeModulesDir = path.join(rootDir, 'node_modules');
-const srcDir = path.join(rootDir, 'build', 'src');
-const testDir = path.join(rootDir, 'build', 'test');
-const nodeBin = process.argv[0];
-const playwrightBin = path.join(tmpDir, 'node_modules', '@playwright', 'test', 'cli.js');
-
-function main() {
+async function main() {
extract();
-
- // Tests need to be run sequentially since they interact with the same daemon instance.
- // Arguments are forwarded to playwright to make it possible to run specific tests.
- const args = [playwrightBin, 'test', '--workers', '1', ...process.argv.slice(2)];
- const result = spawnSync(nodeBin, args, { encoding: 'utf8', cwd: tmpDir });
+ const code = await runTests();
removeTmpDir();
- handleResult(result);
+ process.exit(code);
}
function extract() {
+ const rootDir = path.join(__dirname, '..');
+ const nodeModulesDir = path.join(rootDir, 'node_modules');
+ const srcDir = path.join(rootDir, 'build', 'src');
+ const testDir = path.join(rootDir, 'build', 'test');
+
// Remove old directory if already existing and create new clean one
removeTmpDir();
fs.mkdirSync(tmpDir);
@@ -53,26 +47,38 @@ function copyRecursively(source: string, target: string) {
}
}
-function handleResult(result: SpawnSyncReturns<string>) {
- // Forward all output from playwright
- console.log(result.stdout);
- console.error(result.stderr);
- if (result.error) {
- console.error(result.error);
- }
+function runTests(): Promise<number> {
+ const nodeBin = process.argv[0];
+ const playwrightBin = path.join(tmpDir, 'node_modules', '@playwright', 'test', 'cli.js');
+ const configPath = path.join(tmpDir, 'test', 'e2e', 'installed', 'playwright.config.js');
- // Exit with the same exit code as playwright
- if (result.status === null) {
- process.exit(1);
- } else {
- process.exit(result.status);
- }
+ return new Promise((resolve) => {
+ // Tests need to be run sequentially since they interact with the same daemon instance.
+ // Arguments are forwarded to playwright to make it possible to run specific tests.
+ const args = [playwrightBin, 'test', '-x', '-c', configPath, ...process.argv.slice(2)];
+ const proc = spawn(nodeBin, args, { cwd: tmpDir });
+
+ proc.stdout.on('data', (data) => console.log(data.toString()));
+ proc.stderr.on('data', (data) => console.error(data.toString()));
+ proc.on('close', (code, signal) => {
+ if (signal) {
+ console.log('Received signal:', signal);
+ }
+
+ resolve(code ?? (signal ? 1 : 0));
+ });
+ });
}
function removeTmpDir() {
if (fs.existsSync(tmpDir)) {
- fs.rmSync(tmpDir, { recursive: true });
+ try {
+ fs.rmSync(tmpDir, { recursive: true });
+ } catch (e) {
+ const error = e as Error;
+ console.error('Failed to remove tmp dir:', error.message);
+ }
}
}
-main();
+void main();
diff --git a/gui/test/e2e/installed/playwright.config.ts b/gui/test/e2e/installed/playwright.config.ts
new file mode 100644
index 0000000000..209838beb1
--- /dev/null
+++ b/gui/test/e2e/installed/playwright.config.ts
@@ -0,0 +1,10 @@
+import { defineConfig } from "@playwright/test";
+
+export default defineConfig({
+ testDir: process.cwd(),
+ timeout: 60_000,
+ workers: 1,
+ expect: {
+ timeout: 30_000,
+ },
+});
diff --git a/gui/test/e2e/installed/state-dependent/login.spec.ts b/gui/test/e2e/installed/state-dependent/login.spec.ts
index 4a4edeadf8..9b1642dbd4 100644
--- a/gui/test/e2e/installed/state-dependent/login.spec.ts
+++ b/gui/test/e2e/installed/state-dependent/login.spec.ts
@@ -37,12 +37,10 @@ test('App should fail to login', async () => {
await loginInput.fill('1234 1234 1324 1234');
await loginInput.press('Enter');
- await expect(title).toHaveText('Logging in...');
- await expect(subtitle).toHaveText('Checking account number');
await expect(title).toHaveText('Login failed');
await expect(subtitle).toHaveText('Invalid account number');
- loginInput.fill('');
+ await loginInput.fill('');
});
test('App should create account', async () => {
@@ -52,8 +50,6 @@ test('App should create account', async () => {
const subtitle = page.getByTestId('subtitle');
await page.getByText('Create account').click();
- await expect(title).toHaveText('Creating account...');
- await expect(subtitle).toHaveText('Please wait');
await expect(title).toHaveText('Account created');
await expect(subtitle).toHaveText('Logged in');
@@ -87,8 +83,6 @@ test('App should log in', async () => {
await loginInput.type(process.env.ACCOUNT_NUMBER!);
await loginInput.press('Enter');
- await expect(title).toHaveText('Logging in...');
- await expect(subtitle).toHaveText('Checking account number');
await expect(title).toHaveText('Logged in');
await expect(subtitle).toHaveText('Valid account number');
@@ -132,8 +126,6 @@ test('App should log in to expired account', async () => {
await loginInput.type(accountNumber);
await loginInput.press('Enter');
- await expect(title).toHaveText('Logging in...');
- await expect(subtitle).toHaveText('Checking account number');
await expect(title).toHaveText('Logged in');
await expect(subtitle).toHaveText('Valid account number');