generated from obsidianmd/obsidian-sample-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed bug whereby when copying multiple lines each without a block ID , only block links (without the content of the lines) would get copied for the first and last lines. - Added infrastructure for automated testing using Webdriver.io, and added two initial tests.
- Loading branch information
Showing
9 changed files
with
3,676 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ main.js | |
|
||
# obsidian | ||
data.json | ||
|
||
# tests | ||
test/empty_vault |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import esbuild from "esbuild"; | ||
import process from "process"; | ||
import builtins from 'builtin-modules' | ||
|
||
const banner = | ||
`/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD | ||
if you want to view the source, please visit the github repository of this plugin | ||
*/ | ||
`; | ||
|
||
const prod = (process.argv[2] === 'production'); | ||
|
||
esbuild.build({ | ||
banner: { | ||
js: banner, | ||
}, | ||
entryPoints: ['main.ts'], | ||
bundle: true, | ||
external: [ | ||
'obsidian', | ||
'electron', | ||
'@codemirror/autocomplete', | ||
'@codemirror/closebrackets', | ||
'@codemirror/collab', | ||
'@codemirror/commands', | ||
'@codemirror/comment', | ||
'@codemirror/fold', | ||
'@codemirror/gutter', | ||
'@codemirror/highlight', | ||
'@codemirror/history', | ||
'@codemirror/language', | ||
'@codemirror/lint', | ||
'@codemirror/matchbrackets', | ||
'@codemirror/panel', | ||
'@codemirror/rangeset', | ||
'@codemirror/rectangular-selection', | ||
'@codemirror/search', | ||
'@codemirror/state', | ||
'@codemirror/stream-parser', | ||
'@codemirror/text', | ||
'@codemirror/tooltip', | ||
'@codemirror/view', | ||
...builtins], | ||
format: 'cjs', | ||
watch: !prod, | ||
target: 'es2016', | ||
logLevel: "info", | ||
sourcemap: prod ? false : 'inline', | ||
treeShaking: true, | ||
outfile: 'main.js', | ||
}).catch(() => process.exit(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"id": "obsidian-carry-forward", | ||
"name": "Carry-Forward", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"minAppVersion": "0.13.19", | ||
"description": "An Obsidian Notes plugin for generating and copying block IDs and for copying lines with links to the copied line.", | ||
"author": "Obsidian", | ||
"authorUrl": "https://obsidian.md/about", | ||
"author": "Jacob Levernier", | ||
"authorUrl": "https://github.com/jglev/obsidian-carry-forward", | ||
"isDesktopOnly": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
{ | ||
"name": "obsidian-carry-forward", | ||
"version": "1.4.0", | ||
"description": "An Obsidian Notes plugin for generating and copying block IDs, and copying lines with a link to the copied line.", | ||
"main": "main.js", | ||
"scripts": { | ||
"dev": "rollup --config rollup.config.js -w", | ||
"build": "rollup --config rollup.config.js --environment BUILD:production" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/node": "^14.14.37", | ||
"obsidian": "^0.12.0", | ||
"rollup": "^2.32.1", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
} | ||
"name": "obsidian-carry-forward", | ||
"version": "1.4.1", | ||
"description": "An Obsidian Notes plugin for generating and copying block IDs, and copying lines with a link to the copied line.", | ||
"main": "main.js", | ||
"scripts": { | ||
"dev": "node esbuild.config.mjs", | ||
"version": "node version-bump.mjs && git add manifest.json versions.json", | ||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", | ||
"test": "rm -rf test/empty_vault && yarn run build && mkdir -p test/empty_vault/.obsidian/plugins/sample-plugin && cp manifest.json styles.css main.js test/empty_vault/.obsidian/plugins/sample-plugin && npx wdio run wdio.conf.js" | ||
}, | ||
"keywords": [], | ||
"author": "Jacob Levernier", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^14.14.37", | ||
"@typescript-eslint/eslint-plugin": "^5.2.0", | ||
"@typescript-eslint/parser": "^5.2.0", | ||
"@wdio/cli": "^7.16.15", | ||
"@wdio/local-runner": "^7.16.15", | ||
"@wdio/mocha-framework": "^7.16.15", | ||
"@wdio/selenium-standalone-service": "^7.16.14", | ||
"@wdio/spec-reporter": "^7.16.14", | ||
"builtin-modules": "^3.2.0", | ||
"chai": "^4.3.6", | ||
"chromedriver": "^98.0.1", | ||
"esbuild": "0.13.12", | ||
"obsidian": "^0.12.0", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4", | ||
"wdio-chromedriver-service": "^7.2.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
const { assert } = require("chai"); | ||
const fs = require("fs"); | ||
|
||
// Note: Supported keyboard key names can be found here: | ||
// https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions | ||
|
||
async function sleep(seconds) { | ||
return new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
} | ||
|
||
describe("Plugin", function () { | ||
this.timeout(60 * 1000); | ||
|
||
this.beforeAll(async function () { | ||
await browser; | ||
|
||
// These steps are from | ||
// https://github.com/trashhalo/obsidian-plugin-e2e-test/blob/master/test/spec.js : | ||
|
||
// Open the vault, avoiding working with a File Chooser modal: | ||
await browser.execute( | ||
"require('electron').ipcRenderer.sendSync('vaultOpen', 'test/empty_vault', false)" | ||
); | ||
await sleep(2); | ||
|
||
// Disable safemode and enable the plugin: | ||
await browser.execute( | ||
"app.plugins.setEnable(true);app.plugins.enablePlugin('obsidian-carry-forward')" | ||
); | ||
|
||
// Dismiss warning model: | ||
await browser.$(".modal-button-container button:last-child").click(); | ||
await sleep(0.5); | ||
|
||
// Change the default settings text: | ||
await (await browser.$$('.vertical-tab-header-group')[1]).$('.vertical-tab-nav-item').click(); | ||
await browser.$('.setting-item-control').click(); | ||
await browser.keys('here'); | ||
await sleep(1); | ||
|
||
// Exit settings: | ||
await browser.$(".modal-close-button").click(); | ||
}) | ||
|
||
beforeEach(async function () { | ||
await browser; | ||
// Create a new file: | ||
await browser.$('.workspace').keys(['Control', 'n']); | ||
}); | ||
|
||
afterEach(async function () { | ||
await browser; | ||
await browser.keys(['Escape']); // Close any open dialog box. | ||
await sleep(0.5); | ||
await browser.keys(['Control', 'p']); // Open the Command Palette | ||
await sleep(0.5); | ||
await browser.$(".prompt-input").keys("Delete current file"); | ||
await sleep(0.5); | ||
await browser.$(".suggestion-item.is-selected").click(); | ||
await sleep(1); | ||
await browser.$$('.mod-warning')[1].click(); | ||
await sleep(1); | ||
}); | ||
|
||
it("adds commands", async function () { | ||
await browser.$('.view-content').keys(['Control', 'p']); | ||
await sleep(0.5); | ||
await browser.$(".prompt-input").keys("Carry Forward"); | ||
const commands = (await browser.$$(".suggestion-item")).length; | ||
assert(commands === 12, 'Wrong number of commands in Command Palette'); | ||
}); | ||
|
||
it("correctly copies the contents of all four lines in a block", async function () { | ||
const testText = `- Lorem ipsum 1 | ||
- Lorem ipsum 2 | ||
- Lorem ipsum 3 | ||
- Lorem ipsum 4 | ||
`; | ||
await browser.$('.view-content').click(); | ||
await browser.$('.view-content').keys(testText); | ||
|
||
// Select text: | ||
await browser.$('.CodeMirror-line').keys(['ArrowUp']); | ||
await browser.$('.CodeMirror-line').keys(['End']); | ||
await browser.$('.CodeMirror-line').keys(['Shift', 'ArrowUp']); | ||
await browser.$('.CodeMirror-line').keys(['Shift', 'ArrowUp']); | ||
await browser.$('.CodeMirror-line').keys(['Shift', 'ArrowUp']); | ||
await browser.$('.CodeMirror-line').keys(['Shift', 'Home']); | ||
|
||
await browser.$('.view-content').keys(['Control', 'p']); | ||
await sleep(1); | ||
await browser.$(".prompt-input").keys("Carry Forward: Copy selection with each line linked to its copied source (default link text)"); | ||
await browser.$(".suggestion-item").click(); | ||
await sleep(1); | ||
|
||
// Check the contents of the clipboard: | ||
await $('.view-content').click({ button: "right" }); | ||
await sleep(1); | ||
await $$('.menu-item')[4].click(); // "Select all" | ||
|
||
await $('.view-content').click({ button: "right" }); | ||
await sleep(1); | ||
await $$('.menu-item')[4].click(); // "Paste" | ||
|
||
const pastedText = await $('.view-content').getText(); | ||
|
||
console.log(101, pastedText); | ||
|
||
const testTextSplit = testText.split(/\r?\n/); | ||
const pastedTextSplit = pastedText.split(/\r?\n/); | ||
|
||
assert(pastedTextSplit[0 + 1].startsWith(testTextSplit[0]), `Line 0 ("${testTextSplit[0]}") is not the same ("${pastedTextSplit[0 + 1]}")`); | ||
assert(pastedTextSplit[0 + 1].endsWith('|here]])'), `Line 0 ("${pastedTextSplit[0 + 1]}") does not end with "|here]])")`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.