This commit is contained in:
zhanggy committed 2025-11-05 14:46:49 +08:00
1 parent fc250c54ed
commit 5eec516459
62 files changed
+3912 -3376

No files matched your search

+39 -38
View File
@@ -1,17 +1,18 @@
import * as base from '@playwright/test'
import { _electron as electron, Page, ElectronApplication } from 'playwright'
import { join } from 'path'
import { main } from '../package.json'
import TestUtil from './testUtil.mjs'
import type { ElectronApplication, Page } from 'playwright';
import { join } from 'node:path';
import * as base from '@playwright/test';
import { _electron as electron } from 'playwright';
import { main } from '../package.json';
import TestUtil from './testUtil.mjs';
let appElectron: ElectronApplication
let page: Page
let appElectron: ElectronApplication;
let page: Page;
const __cwd = process.cwd()
const __isCiProcess = process.env.CI === 'true'
const __testPath = join(__cwd, 'tests')
const __testResultPath = join(__testPath, 'results')
const __testScreenshotPath = join(__testResultPath, 'screenshots')
const __cwd = process.cwd();
const __isCiProcess = process.env.CI === 'true';
const __testPath = join(__cwd, 'tests');
const __testResultPath = join(__testPath, 'results');
const __testScreenshotPath = join(__testResultPath, 'screenshots');
export const beforeAll = async () => {
// Open Electron app from build directory
@@ -23,60 +24,60 @@ export const beforeAll = async () => {
'--ignore-certificate-errors',
'--ignore-ssl-errors',
'--ignore-blocklist',
'--ignore-gpu-blocklist'
'--ignore-gpu-blocklist',
],
locale: 'en-US',
colorScheme: 'light',
env: {
...process.env,
NODE_ENV: 'production'
}
})
page = await appElectron.firstWindow()
NODE_ENV: 'production',
},
});
page = await appElectron.firstWindow();
await page.waitForEvent('load')
await page.waitForEvent('load');
page.on('console', console.log)
page.on('pageerror', console.log)
page.on('console', console.log);
page.on('pageerror', console.log);
const evaluateResult = await appElectron.evaluate(
async ({ app, BrowserWindow }) => {
const currentWindow = BrowserWindow.getFocusedWindow()
const currentWindow = BrowserWindow.getFocusedWindow();
// Fix window position for testing
currentWindow.setPosition(50, 50)
currentWindow.setSize(1080, 560)
currentWindow.setPosition(50, 50);
currentWindow.setSize(1080, 560);
return {
packaged: app.isPackaged,
dataPath: app.getPath('userData')
}
}
)
dataPath: app.getPath('userData'),
};
},
);
base.expect(evaluateResult.packaged, 'app is not packaged').toBe(false)
}
base.expect(evaluateResult.packaged, 'app is not packaged').toBe(false);
};
export const afterAll = async () => {
await appElectron.close()
}
await appElectron.close();
};
export const test = base.test.extend({
// eslint-disable-next-line no-empty-pattern
page: async ({}, use) => {
await use(page)
await use(page);
},
// @ts-expect-error: `util` is not using types in playwright
util: async ({ page }, use, testInfo) => {
await use(new TestUtil(page, testInfo, __testScreenshotPath))
}
})
await use(new TestUtil(page, testInfo, __testScreenshotPath));
},
});
export const expect = base.expect
export const expect = base.expect;
export default {
test,
expect,
beforeAll,
afterAll
}
afterAll,
};