From 0e0193997b963693f3ffb1d99b5077693b76c6c1 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 16 Jul 2024 02:12:30 +0300 Subject: [PATCH] test(e2e): basic e2e config for wdio --- .gitignore | 1 + package.json | 128 +++++++++++++++++++++++-------------------- test/e2e/e2e.spec.js | 14 +++++ test/e2e/helpers.js | 38 +++++++++++++ tsconfig.json | 5 +- vitest.config.mjs | 7 ++- wdio.conf.js | 38 +++++++++++++ 7 files changed, 167 insertions(+), 64 deletions(-) create mode 100644 test/e2e/e2e.spec.js create mode 100644 test/e2e/helpers.js create mode 100644 wdio.conf.js diff --git a/.gitignore b/.gitignore index 8dc6a8f..fa273d8 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/package.json b/package.json index 1b8d1d7..5d4b1b5 100644 --- a/package.json +++ b/package.json @@ -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" - } -} \ No newline at end of file + "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" + } +} diff --git a/test/e2e/e2e.spec.js b/test/e2e/e2e.spec.js new file mode 100644 index 0000000..5c539dc --- /dev/null +++ b/test/e2e/e2e.spec.js @@ -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 () => { + }); +}); diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js new file mode 100644 index 0000000..1c113d3 --- /dev/null +++ b/test/e2e/helpers.js @@ -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: ; + 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 }); + } +}; diff --git a/tsconfig.json b/tsconfig.json index b904126..60e9cdd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,9 @@ ] }, "include": [ - "**/*.ts" + "**/*.ts" + ], + "exclude": [ + "test/e2e/**" ] } diff --git a/vitest.config.mjs b/vitest.config.mjs index ce1a81a..0ac78c2 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -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', @@ -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') diff --git a/wdio.conf.js b/wdio.conf.js new file mode 100644 index 0000000..0564299 --- /dev/null +++ b/wdio.conf.js @@ -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, + }, +};