Skip to content

Commit

Permalink
1.4.1 (#16)
Browse files Browse the repository at this point in the history
- 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
jglev committed Feb 24, 2022
1 parent b17118d commit b6f827b
Show file tree
Hide file tree
Showing 9 changed files with 3,676 additions and 205 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,6 @@ main.js

# obsidian
data.json

# tests
test/empty_vault
52 changes: 52 additions & 0 deletions esbuild.config.mjs
@@ -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));
1 change: 1 addition & 0 deletions main.ts
Expand Up @@ -99,6 +99,7 @@ const copyForwardLines = async (
}

if (
selections.length > 1 &&
(lineNumber === minLine || lineNumber === maxLine) &&
!(minLine === maxLine && cursorFrom.ch === cursorTo.ch)
) {
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
@@ -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
}
52 changes: 31 additions & 21 deletions package.json
@@ -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"
}
}
115 changes: 115 additions & 0 deletions test/specs/example.e2e.js
@@ -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]])")`);
});
});
3 changes: 2 additions & 1 deletion versions.json
Expand Up @@ -4,5 +4,6 @@
"1.1.0": "0.12.12",
"1.2.0": "0.13.14",
"1.3.0": "0.13.19",
"1.4.0": "0.13.19"
"1.4.0": "0.13.19",
"1.4.1": "0.13.19"
}

0 comments on commit b6f827b

Please sign in to comment.