Skip to content

Commit

Permalink
test(e2e): basic e2e config for wdio
Browse files Browse the repository at this point in the history
  • Loading branch information
bandantonio committed Jul 15, 2024
1 parent e5b071a commit 0e01939
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ node_modules

# tests
coverage
test_e2e_vault/
# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js
Expand Down
128 changes: 68 additions & 60 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
{
"name": "obsidian-apple-books-highlights-plugin",
"version": "1.3.0",
"description": "Import highlights and notes from your Apple Books to Obsidian",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"lint": "eslint . --ext .ts",
"version": "node version-bump.mjs",
"test": "vitest",
"coverage": "vitest run --coverage",
"db:generate": "drizzle-kit generate:sqlite",
"db:migrate": "npx tsx src/db/migrate.ts",
"db:seed": "npx tsx src/db/seed.ts",
"prepare": "husky"
},
"keywords": [
"obsidian",
"plugin",
"apple",
"books",
"applebooks",
"iBooks",
"highlights",
"notes",
"importer"
],
"author": "bandantonio",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/bandantonio/obsidian-apple-books-highlights-plugin.git"
},
"engines": {
"node": ">=20.8.0",
"npm": ">=10.0.0"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.10",
"@types/node": "^18.4.1",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"@vitest/coverage-istanbul": "^1.5.1",
"better-sqlite3": "^9.5.0",
"builtin-modules": "3.3.0",
"drizzle-kit": "^0.20.17",
"drizzle-orm": "^0.30.9",
"esbuild": "0.17.3",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4",
"vitest": "^1.5.1"
},
"dependencies": {
"dayjs": "^1.11.10",
"handlebars": "^4.7.8"
}
}
"name": "obsidian-apple-books-highlights-plugin",
"version": "1.3.0",
"description": "Import highlights and notes from your Apple Books to Obsidian",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"lint": "eslint . --ext .ts",
"version": "node version-bump.mjs",
"test": "vitest",
"test:e2e": "wdio run ./wdio.conf.js",
"coverage": "vitest run --coverage",
"db:generate": "drizzle-kit generate:sqlite",
"db:migrate": "npx tsx src/db/migrate.ts",
"db:seed": "npx tsx src/db/seed.ts",
"prepare": "husky"
},
"keywords": [
"obsidian",
"plugin",
"apple",
"books",
"applebooks",
"iBooks",
"highlights",
"notes",
"importer"
],
"author": "bandantonio",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/bandantonio/obsidian-apple-books-highlights-plugin.git"
},
"engines": {
"node": ">=20.8.0",
"npm": ">=10.0.0"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.10",
"@types/node": "^18.4.1",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"@vitest/coverage-istanbul": "^1.5.1",
"@wdio/cli": "^8.36.1",
"@wdio/local-runner": "^8.36.1",
"@wdio/mocha-framework": "^8.36.1",
"@wdio/spec-reporter": "^8.36.1",
"better-sqlite3": "^11.1.1",
"builtin-modules": "3.3.0",
"drizzle-kit": "^0.20.17",
"drizzle-orm": "^0.30.9",
"electron": "^30.0.3",
"esbuild": "0.17.3",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4",
"vitest": "^1.5.1",
"wdio-electron-service": "^6.5.0",
"webdriverio": "^8.36.1"
},
"dependencies": {
"dayjs": "^1.11.10",
"handlebars": "^4.7.8"
}
}
14 changes: 14 additions & 0 deletions test/e2e/e2e.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const helpers = require('./helpers');

beforeEach(async () => {
await helpers.initializeTestVault();
});

afterEach(() => {
helpers.cleanupTestVault();
});

describe('Test plugin within Obsidian instance', () => {
it('Ensure plugin is enabled', async () => {
});
});
38 changes: 38 additions & 0 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require("fs");
const { Key } = require('webdriverio');

module.exports = {
sleep: async (seconds) => {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
},

initializeTestVault: async () => {
await browser;

await browser.execute(
"require('electron').ipcRenderer.sendSync('vault-open', 'test/e2e/test_e2e_vault', true)"
);

const pluginsDirectory = "test/e2e/test_e2e_vault/.obsidian/plugins/apple-books-import-highlights";

fs.mkdirSync(pluginsDirectory, { recursive: true });
fs.copyFileSync("manifest.json", `${pluginsDirectory}/manifest.json`);
fs.copyFileSync("main.js", `${pluginsDirectory}/main.js`);
fs.copyFileSync("styles.css", `${pluginsDirectory}/styles.css`);

await module.exports.sleep(3);

// Select the element: <button>Trust author and enable plugins</button>;
await browser.$("div.modal.mod-trust-folder > div.modal-button-container > button:nth-child(1)").click();



// await browser.execute(
// "app.plugins.setEnable(true);app.plugins.enablePlugin('oapple-books-import-highlights')"
// );
},

cleanupTestVault: () => {
fs.rmSync("test/e2e/test_e2e_vault", { recursive: true, force: true });
}
};
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
]
},
"include": [
"**/*.ts"
"**/*.ts"
],
"exclude": [
"test/e2e/**"
]
}
7 changes: 4 additions & 3 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig, configDefaults } from 'vitest/config';
export default defineConfig({
test: {
include: ['test/**/*.spec.ts'],
exclude: [...configDefaults.exclude, ".direnv/**/*"],
exclude: [...configDefaults.exclude, '.direnv/**/*', 'test/e2e/'],
coverage: {
enabled: true,
provider: 'istanbul',
Expand All @@ -15,8 +15,9 @@ export default defineConfig({
'esbuild.config.mjs',
'version-bump.mjs',
'test/mocks/**/*',
'src/db/**/*',
]
'test/e2e/',
'src/db/**/*'
],
},
alias: {
obsidian: path.resolve(__dirname, 'test/mocks/obsidian.ts')
Expand Down
38 changes: 38 additions & 0 deletions wdio.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
exports.config = {
specs: ["./test/e2e/*.spec.js"],
exclude: [],
services: ["electron"],
capabilities: [
// {
// maxInstances: 1,
// browserName: "chrome",
// "goog:chromeOptions": {
// binary: "/Applications/Obsidian.app/Contents/MacOS/Obsidian",
// args: process.env.CI ? ["headless"] : [],
// },
// acceptInsecureCerts: true,
// },
{
browserName: "electron",
browserVersion: "28.2.3",
"wdio:electronServiceOptions": {
// custom application args
appBinaryPath:
"/Applications/Obsidian.app/Contents/MacOS/Obsidian",
appArgs: [],
},
},
],
logLevel: "info",
bail: 0,
baseUrl: "http://localhost",
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 0,
framework: "mocha",
reporters: ["spec"],
mochaOpts: {
ui: "bdd",
timeout: 60000,
},
};

0 comments on commit 0e01939

Please sign in to comment.