Update test configs

This commit is contained in:
Jesse Hines 2025-08-03 14:21:26 -04:00
parent 08ffc26dce
commit 66ca2bfc37
No known key found for this signature in database
5 changed files with 84 additions and 71 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.obsidian-cache .obsidian-cache
.env
# Don't include the compiled main.js file in the repo. # Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead. # They should be uploaded to GitHub releases instead.
main.js main.js

1
package-lock.json generated
View file

@ -27,6 +27,7 @@
"chai": "^5.2.1", "chai": "^5.2.1",
"esbuild": "^0.25.8", "esbuild": "^0.25.8",
"eslint": "^9.32.0", "eslint": "^9.32.0",
"lodash.merge": "^4.6.2",
"mocha": "^11.7.1", "mocha": "^11.7.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"obsidian": "latest", "obsidian": "latest",

View file

@ -11,8 +11,8 @@
"lint": "eslint src test", "lint": "eslint src test",
"test": "run-s test:*", "test": "run-s test:*",
"test:unit": "tsc --noEmit && mocha", "test:unit": "tsc --noEmit && mocha",
"test:e2e": "npm run build && npx wdio run ./wdio.conf.mts", "test:e2e": "npx wdio run ./wdio.conf.mts",
"test-extra:android": "npm run build && npx wdio run ./wdio.mobile.conf.mts" "test-extra:android": "npx wdio run ./wdio.mobile.conf.mts"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
@ -33,6 +33,7 @@
"chai": "^5.2.1", "chai": "^5.2.1",
"esbuild": "^0.25.8", "esbuild": "^0.25.8",
"eslint": "^9.32.0", "eslint": "^9.32.0",
"lodash.merge": "^4.6.2",
"mocha": "^11.7.1", "mocha": "^11.7.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"obsidian": "latest", "obsidian": "latest",

View file

@ -1,87 +1,86 @@
import * as path from "path" import * as path from "path"
import { obsidianBetaAvailable, resolveObsidianVersions } from "wdio-obsidian-service"; import { parseObsidianVersions, obsidianBetaAvailable } from "wdio-obsidian-service";
import merge from "lodash.merge";
import { env } from "process";
// wdio-obsidian-service will download Obsidian versions into this directory
const cacheDir = path.resolve(".obsidian-cache"); const cacheDir = path.resolve(".obsidian-cache");
let versions: [string, string][]; // [appVersion, installerVersion][] // choose Obsidian versions to test
if (process.env.OBSIDIAN_VERSIONS) { let defaultVersions = "earliest/earliest latest/latest";
// Space separated list of appVersion/installerVersion, e.g. "1.7.7/latest latest/earliest" if (await obsidianBetaAvailable({cacheDir})) {
versions = process.env.OBSIDIAN_VERSIONS.split(/[ ,]+/).map(v => { defaultVersions += " latest-beta/latest"
const [app, installer = "earliest"] = v.split("/"); // default to earliest installer }
return [app, installer]; const desktopVersions = await parseObsidianVersions(
}) env.OBSIDIAN_VERSIONS ?? defaultVersions,
} else if (process.env.CI) { {cacheDir},
// Running in GitHub CI. You can use RUNNER_OS to select different versions on different );
// platforms in the workflow matrix if you want const mobileVersions = await parseObsidianVersions(
versions = [["earliest", "earliest"], ["latest", "latest"]]; env.OBSIDIAN_MOBILE_VERSIONS ?? env.OBSIDIAN_VERSIONS ?? defaultVersions,
if (await obsidianBetaAvailable(cacheDir)) { {cacheDir},
versions.push(["latest-beta", "latest"]); );
} if (env.CI) {
// Print the resolved Obsidian versions to use as the workflow cache key // Print the resolved Obsidian versions to use as the workflow cache key
// (see .github/workflows/test.yaml) // (see .github/workflows/test.yaml)
for (let [app, installer] of versions) { console.log("obsidian-cache-key:", JSON.stringify([desktopVersions, mobileVersions]));
[app, installer] = await resolveObsidianVersions(app, installer, cacheDir); }
console.log(`${app}/${installer}`);
} const common: WebdriverIO.Capabilities = {
} else { browserName: 'obsidian',
versions = [["earliest", "earliest"], ["latest", "latest"]]; 'wdio:obsidianOptions': {
plugins: [
".",
{id: "obsidian-excalidraw-plugin", enabled: false},
{id: "home-tab", enabled: false},
{id: "obsidian-kanban", enabled: false},
],
vault: "./test/vault",
},
} }
export const config: WebdriverIO.Config = { export const config: WebdriverIO.Config = {
runner: 'local', runner: 'local',
framework: 'mocha', framework: 'mocha',
specs: ['./test/specs/**/*.e2e.ts'],
// How many instances of Obsidian should be launched in parallel during testing.
maxInstances: Number(process.env["WDIO_MAX_INSTANCES"] || 4),
capabilities: versions.flatMap(([appVersion, installerVersion]) => { specs: ['./test/specs/**/*.e2e.ts'],
const common: WebdriverIO.Capabilities = {
browserName: 'obsidian', // How many instances of Obsidian should be launched in parallel during testing.
browserVersion: appVersion, maxInstances: Number(env.WDIO_MAX_INSTANCES || 4),
// "matrix" to test your plugin on multiple Obsidian versions and with emulateMobile
capabilities: [
...desktopVersions.map(([appVersion, installerVersion]) => merge({}, common, {
'wdio:obsidianOptions': { 'wdio:obsidianOptions': {
installerVersion: installerVersion, appVersion, installerVersion,
plugins: [
".",
{id: "obsidian-excalidraw-plugin", enabled: false},
{id: "home-tab", enabled: false},
{id: "obsidian-kanban", enabled: false},
],
vault: "./test/vault",
}, },
} })),
return [ // Test the plugin on the emulated mobile UI.
{...common}, ...mobileVersions.map(([appVersion, installerVersion]) => merge({}, common, {
{ 'wdio:obsidianOptions': {
...common, appVersion, installerVersion,
'wdio:obsidianOptions': { emulateMobile: true,
...common['wdio:obsidianOptions'], },
emulateMobile: true, 'goog:chromeOptions': {
}, mobileEmulation: {
'goog:chromeOptions': { deviceMetrics: {width: 390, height: 844, touch: false},
mobileEmulation: {
// can also set deviceName: "iPad" etc. instead of hard-coding size
deviceMetrics: {width: 390, height: 844, touch: false},
},
}, },
}, },
] })),
}), ],
services: ["obsidian"], services: ["obsidian"],
reporters: ['obsidian'], reporters: ['obsidian'],
cacheDir: cacheDir,
bail: 2, bail: 2,
mochaOpts: { mochaOpts: {
ui: 'bdd', ui: 'bdd',
timeout: 60000, timeout: 60 * 1000,
// Retry flaky tests
// TODO: Fix the timing issues
retries: 4, retries: 4,
bail: true, bail: true,
}, },
waitforInterval: 250, waitforInterval: 250,
waitforTimeout: 5 * 1000, waitforTimeout: 5 * 1000,
logLevel: "warn", logLevel: "warn",
cacheDir: cacheDir,
} }

View file

@ -1,30 +1,40 @@
import * as path from "path" import * as path from "path"
import { parseObsidianVersions } from "wdio-obsidian-service";
import { env } from "process";
let versionsToTest: string[] const cacheDir = path.resolve(".obsidian-cache");
if (process.env.OBSIDIAN_VERSIONS) {
versionsToTest = process.env.OBSIDIAN_VERSIONS.split(/[ ,]+/) // choose Obsidian versions to test
} else { // note: beta versions aren't available for the Android app
versionsToTest = ["earliest", "latest"]; let defaultVersions = "earliest/earliest latest/latest";
const versions = await parseObsidianVersions(
env.OBSIDIAN_MOBILE_VERSIONS ?? env.OBSIDIAN_VERSIONS ?? defaultVersions,
{cacheDir},
);
if (env.CI) {
console.log("obsidian-cache-key:", JSON.stringify(versions));
} }
export const config: WebdriverIO.Config = { export const config: WebdriverIO.Config = {
runner: 'local', runner: 'local',
framework: 'mocha', framework: 'mocha',
maxInstances: 1, // can't do android tests in parallel :(
specs: ['./test/specs/**/*.e2e.ts'], specs: ['./test/specs/**/*.e2e.ts'],
hostname: 'localhost', maxInstances: 1, // Parallel tests don't work under appium
port: parseInt(process.env.APPIUM_PORT || "4723"), hostname: env.APPIUM_HOST || 'localhost',
port: parseInt(env.APPIUM_PORT || "4723"),
capabilities: versionsToTest.map((version) => ({ // (installerVersion isn't relevant for the mobile app)
capabilities: versions.map<WebdriverIO.Capabilities>(([appVersion]) => ({
browserName: "obsidian", browserName: "obsidian",
browserVersion: version,
platformName: 'Android', platformName: 'Android',
'appium:automationName': 'UiAutomator2', 'appium:automationName': 'UiAutomator2',
'appium:avd': "obsidian_test", 'appium:avd': "obsidian_test",
'appium:enforceAppInstall': true, 'appium:enforceAppInstall': true,
'appium:adbExecTimeout': 60 * 1000, 'appium:adbExecTimeout': 60 * 1000,
'wdio:obsidianOptions': { 'wdio:obsidianOptions': {
appVersion: appVersion,
plugins: [ plugins: [
".", ".",
{id: "obsidian-excalidraw-plugin", enabled: false}, {id: "obsidian-excalidraw-plugin", enabled: false},
@ -43,15 +53,16 @@ export const config: WebdriverIO.Config = {
], ],
reporters: ["obsidian"], reporters: ["obsidian"],
cacheDir: path.resolve(".obsidian-cache"),
bail: 2, bail: 2,
mochaOpts: { mochaOpts: {
ui: 'bdd', ui: 'bdd',
timeout: 60000, timeout: 60 * 1000,
retries: 4, retries: 4,
bail: true, bail: true,
}, },
waitforInterval: 250, waitforInterval: 250,
waitforTimeout: 5 * 1000, waitforTimeout: 5 * 1000,
logLevel: "warn", logLevel: "warn",
cacheDir: cacheDir,
} }