From 1c035f6053f21944ab5e858db72cea993c56dc8a Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Wed, 21 Aug 2024 20:32:37 -0400 Subject: [PATCH 1/9] added extra integration test logic --- __integration__/custom-commands.test.ts | 1 + __integration__/main.test.ts | 32 ++++++++++++++- __integration__/utils.test.ts | 2 + __integration__/yaml-rule.test.ts | 40 +++++++++++++++++++ .../add-blank-line-after-yaml/no-yaml.md | 2 + .../add-blank-line-after-yaml/yaml-blanks.md | 7 ++++ .../add-blank-line-after-yaml/yaml.md | 4 ++ 7 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 __integration__/yaml-rule.test.ts create mode 100644 test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.md create mode 100644 test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.md create mode 100644 test-vault/yaml-rules/add-blank-line-after-yaml/yaml.md diff --git a/__integration__/custom-commands.test.ts b/__integration__/custom-commands.test.ts index 3e405961..01c117bc 100644 --- a/__integration__/custom-commands.test.ts +++ b/__integration__/custom-commands.test.ts @@ -8,6 +8,7 @@ export const customCommandTestCases: IntegrationTestCase[] = [ name: 'Advanced Tables custom command running after the linting of a file should run just fine even though it relies on the cache', filePath: 'custom-commands/table-format.md', async setup(plugin: TestLinterPlugin, _: Editor) { + // console.log(editor.getValue()); plugin.plugin.settings.ruleConfigs['consecutive-blank-lines'] = { 'enabled': true, }; diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index 177974c6..d8a46fa4 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -3,6 +3,8 @@ import LinterPlugin from 'src/main'; import {obsidianModeTestCases} from './obsidian-mode.test'; import {setWorkspaceItemMode} from './utils.test'; import {customCommandTestCases} from './custom-commands.test'; +import {obsidianYAMLRuleTestCases} from './yaml-rule.test'; +import {sleep} from './utils.test'; export type IntegrationTestCase = { name: string, @@ -11,17 +13,38 @@ export type IntegrationTestCase = { assertions: (editor: Editor) => void, } +const testTimeout = 15000; + export default class TestLinterPlugin extends Plugin { - regularTests: Array = [...obsidianModeTestCases]; + regularTests: Array = [...obsidianModeTestCases, ...obsidianYAMLRuleTestCases]; afterCacheUpdateTests: Array = [...customCommandTestCases]; plugin: LinterPlugin; + private testsCompleted: number; + // eslint-disable-next-line no-undef + private timeoutId: Timeout = undefined; async onload() { this.addCommand({ id: 'run-linter-tests', name: 'Run Linter Tests', callback: async () => { + if (this.timeoutId != undefined) { + clearTimeout(this.timeoutId); + } + await this.setup(); + + this.timeoutId = setTimeout(() =>{ + const expectedTestCount = this.regularTests.length + this.afterCacheUpdateTests.length; + if (this.testsCompleted != expectedTestCount) { + console.log('❌', `Tests took too long to run with only ${this.testsCompleted} of ${expectedTestCount} tests running in ${testTimeout/1000}s.`); + } else { + console.log(`✅ all ${expectedTestCount} tests have completed in the alloted time.`); + } + }, testTimeout); + + await sleep(500); + await this.runTests(); }, }); @@ -35,6 +58,8 @@ export default class TestLinterPlugin extends Plugin { } else { await this.resetSettings(); } + + this.testsCompleted = 0; } async runTests() { @@ -64,9 +89,11 @@ export default class TestLinterPlugin extends Plugin { await t.assertions(activeLeaf.editor); console.log('✅', t.name); + this.testsCompleted++; } catch (e) { console.log('❌', t.name); console.error(e); + this.testsCompleted++; } await this.resetFileContents(activeLeaf, originalText); @@ -98,9 +125,11 @@ export default class TestLinterPlugin extends Plugin { await t.assertions(activeLeaf.editor); console.log('✅', t.name); + this.testsCompleted++; } catch (e) { console.log('❌', t.name); console.error(e); + this.testsCompleted++; } await that.resetFileContents(activeLeaf, originalText); @@ -135,6 +164,7 @@ export default class TestLinterPlugin extends Plugin { await testPlugin.plugin.runLinterEditor(activeLeaf.editor); } catch (e) { + this.testsCompleted++; console.log('❌', t.name); console.error(e); await testPlugin.resetFileContents(activeLeaf, originalText); diff --git a/__integration__/utils.test.ts b/__integration__/utils.test.ts index 19bc624e..00a37438 100644 --- a/__integration__/utils.test.ts +++ b/__integration__/utils.test.ts @@ -1,5 +1,7 @@ import {App, FileView} from 'obsidian'; +export const sleep = (delay: number) => new Promise((resolve) => setTimeout(resolve, delay)); + export async function setWorkspaceItemMode(app: App, source: boolean) { const view: FileView = app.workspace.getActiveFileView(); if (!view) { diff --git a/__integration__/yaml-rule.test.ts b/__integration__/yaml-rule.test.ts new file mode 100644 index 00000000..ee586af4 --- /dev/null +++ b/__integration__/yaml-rule.test.ts @@ -0,0 +1,40 @@ +import dedent from 'ts-dedent'; +import TestLinterPlugin, {IntegrationTestCase} from './main.test'; +import {Editor} from 'obsidian'; +import expect from 'expect'; + +function addBlankLineAfterSetup(plugin: TestLinterPlugin, _editor: Editor) { + plugin.plugin.settings.ruleConfigs['add-blank-line-after-yaml'] = { + 'enabled': true, + }; +} + +export const obsidianYAMLRuleTestCases: IntegrationTestCase[] = [ + { + name: 'Updating a file with no yaml for adding blank lines after yaml should do nothing', + filePath: 'yaml-rules/add-blank-line-after-yaml/no-yaml.md', + setup: addBlankLineAfterSetup, + assertions: (editor: Editor) =>{ + expect(editor.getValue()).toBe(dedent` + This is a file with no YAML in it. + It remains the same, right? + ${''} + `); + }, + }, + { + name: 'Updating a file with yaml and no blanks for adding blank lines after yaml should get updated', + filePath: 'yaml-rules/add-blank-line-after-yaml/yaml.md', + setup: addBlankLineAfterSetup, + assertions: (editor: Editor) =>{ + expect(editor.getValue()).toBe(dedent` + --- + key: value + --- + ${''} + No blank + ${''} + `); + }, + }, +]; diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.md b/test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.md new file mode 100644 index 00000000..8ae80a3a --- /dev/null +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.md @@ -0,0 +1,2 @@ +This is a file with no YAML in it. +It remains the same, right? diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.md b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.md new file mode 100644 index 00000000..4e59e263 --- /dev/null +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.md @@ -0,0 +1,7 @@ +--- +key: value +--- + + + +No blank \ No newline at end of file diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.md b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.md new file mode 100644 index 00000000..2aed0838 --- /dev/null +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.md @@ -0,0 +1,4 @@ +--- +key: value +--- +No blank From 64ae4637b04af338bdae1cc660d8e307ef52044e Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Wed, 21 Aug 2024 21:50:08 -0400 Subject: [PATCH 2/9] stash commit of changes to get to using linted files instead of text in the integration files --- __integration__/custom-commands.test.ts | 31 ------ __integration__/main.test.ts | 26 +++-- __integration__/obsidian-mode.test.ts | 96 ------------------- __integration__/yaml-rule.test.ts | 19 ---- .../custom-commands/table-format.linted.md | 23 +++++ .../obsidian-mode/edge-case-yaml.linted.md | 55 +++++++++++ test-vault/obsidian-mode/mode-yaml.linted.md | 27 ++++++ .../no-yaml.linted.md | 2 + .../yaml-blanks.linted.md | 7 ++ .../add-blank-line-after-yaml/yaml.linted.md | 4 + 10 files changed, 138 insertions(+), 152 deletions(-) create mode 100644 test-vault/custom-commands/table-format.linted.md create mode 100644 test-vault/obsidian-mode/edge-case-yaml.linted.md create mode 100644 test-vault/obsidian-mode/mode-yaml.linted.md create mode 100644 test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.linted.md create mode 100644 test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.linted.md create mode 100644 test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md diff --git a/__integration__/custom-commands.test.ts b/__integration__/custom-commands.test.ts index 01c117bc..0135080e 100644 --- a/__integration__/custom-commands.test.ts +++ b/__integration__/custom-commands.test.ts @@ -1,14 +1,11 @@ -import dedent from 'ts-dedent'; import TestLinterPlugin, {IntegrationTestCase} from './main.test'; import {Editor} from 'obsidian'; -import expect from 'expect'; export const customCommandTestCases: IntegrationTestCase[] = [ { name: 'Advanced Tables custom command running after the linting of a file should run just fine even though it relies on the cache', filePath: 'custom-commands/table-format.md', async setup(plugin: TestLinterPlugin, _: Editor) { - // console.log(editor.getValue()); plugin.plugin.settings.ruleConfigs['consecutive-blank-lines'] = { 'enabled': true, }; @@ -18,33 +15,5 @@ export const customCommandTestCases: IntegrationTestCase[] = [ 'name': 'Format all tables in this file', }]; }, - async assertions(editor: Editor) { - expect(editor.getValue()).toBe(dedent` - | one | two | three | four | - | ----- | --- | ----- | ------------- | - | 1 | ✓ | | | - | 2 | | ✓ | | - | 3 | | ✓ | ✓ | - | 4 | … | | someting else | - | Total | 100 | 20 | 300000000 | - ${''} - | one | two | three | four | - | ----- | --- | ----- | ------------- | - | 1 | ✓ | | | - | 2 | | ✓ | | - | 3 | | ✓ | ✓ | - | 4 | … | | someting else | - | Total | 100 | 20 | 300000000 | - ${''} - | one | two | three | four | - | ----- | --- | ----- | ------------- | - | 1 | ✓ | | | - | 2 | | ✓ | | - | 3 | | ✓ | ✓ | - | 4 | … | | someting else | - | Total | 100 | 20 | 300000000 | - ${''} - `); - }, }, ]; diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index d8a46fa4..3cd03366 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -4,13 +4,13 @@ import {obsidianModeTestCases} from './obsidian-mode.test'; import {setWorkspaceItemMode} from './utils.test'; import {customCommandTestCases} from './custom-commands.test'; import {obsidianYAMLRuleTestCases} from './yaml-rule.test'; -import {sleep} from './utils.test'; +import expect from 'expect'; export type IntegrationTestCase = { name: string, filePath: string, setup?: (plugin: TestLinterPlugin, editor: Editor) => void, - assertions: (editor: Editor) => void, + assertions?: (editor: Editor) => void, } const testTimeout = 15000; @@ -43,8 +43,6 @@ export default class TestLinterPlugin extends Plugin { } }, testTimeout); - await sleep(500); - await this.runTests(); }, }); @@ -86,7 +84,10 @@ export default class TestLinterPlugin extends Plugin { } await this.plugin.runLinterEditor(activeLeaf.editor); - await t.assertions(activeLeaf.editor); + expect(activeLeaf.editor).toBe(await this.getExpectedContents(t.filePath.replace('.md', '.linted.md'))); + if (t.assertions) { + await t.assertions(activeLeaf.editor); + } console.log('✅', t.name); this.testsCompleted++; @@ -122,7 +123,10 @@ export default class TestLinterPlugin extends Plugin { const t = tests[index]; try { - await t.assertions(activeLeaf.editor); + expect(activeLeaf.editor).toBe(await this.getExpectedContents(t.filePath.replace('.md', '.linted.md'))); + if (t.assertions) { + await t.assertions(activeLeaf.editor); + } console.log('✅', t.name); this.testsCompleted++; @@ -194,6 +198,16 @@ export default class TestLinterPlugin extends Plugin { return activeLeaf; } + private async getExpectedContents(filePath: string): Promise { + const file = this.getFileFromPath(filePath); + if (!file) { + console.error('failed to get file: ' + filePath); + return; + } + + return await this.app.vault.cachedRead(file); + } + private getFileFromPath(filePath: string): TFile { const file = this.app.vault.getAbstractFileByPath(normalizePath(filePath)); if (file instanceof TFile) { diff --git a/__integration__/obsidian-mode.test.ts b/__integration__/obsidian-mode.test.ts index dff89907..c6820c7c 100644 --- a/__integration__/obsidian-mode.test.ts +++ b/__integration__/obsidian-mode.test.ts @@ -1,9 +1,7 @@ -import dedent from 'ts-dedent'; import TestLinterPlugin, {IntegrationTestCase} from './main.test'; import {Editor} from 'obsidian'; import expect from 'expect'; import {setWorkspaceItemMode} from './utils.test'; -import {moment} from 'obsidian'; const cursorStart = 319; @@ -19,38 +17,6 @@ function modeSetup(plugin: TestLinterPlugin, editor: Editor) { } function modeAssertions(editor: Editor) { - expect(editor.getValue()).toBe(dedent` - --- - author: - - Somebody - citation: unknown - cover: https:github.com - datePub: 1993 - device: - - dsi - format: - - epub - priority: 2 - publisher: Pokemon Publisher - readingStatus: easy - related: - researchArea: - - scifi - status: - summary: - tags: - - pokemon - - monsters - title: Pokemon - total: 481 - withProject: - --- - # Heading here... - ${''} - Some text here... - ${''} - `); - // one character was added before the cursor expect(editor.posToOffset(editor.getCursor())).toBe(cursorStart+1); } @@ -105,66 +71,6 @@ function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor) { }; } -function edgeCaseAssertions(editor: Editor) { - expect(editor.getValue()).toBe(dedent` - --- - aliases: - - test - tags: - - test1 - - test2 - related: - - "[[test]]" - - "[[test 2]]" - date: 2024-05-22 - class: "[[test]]" - instructor: "[[test]]" - readings: - - "[[test]]" - - "[[test 2#1.1 test chapter]]" - ${''} - created: ${moment().format('YYYY-MM-DD')} - last_modified: ${moment().format('YYYY-MM-DD')} - --- - ${''} - - Focus on XYZ. - ${''} - # I. Test: - ${''} - ## (Document A, paras [para 2] – [para 8], [para 13] – [para 24]; Document B, para. [3]) - ${''} - ### a. test (*Document A, para. [para 2])*? - ${''} - Lorem ipsum dolor: - ${''} - - **test**: **X** v. **Y** *(the allies)* with support from **Y** - ${''} - \t- Lorem ipsum dolor sit amet + consectetur adipiscing elit. Morbi vel ipsum ipsum - - More info ([test](https://www.example.org)): - ${''} - \t- „quote […] quote.” - ${''} - \t- “quote.” - ${''} - \t- “quote.” - ${''} - - **test**: X v Y - ${''} - - **test:** X v Y - ${''} - - (Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel ipsum ipsum.) - ${''} - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel ipsum ipsum. (Document A, para. [2])? - ${''} - \t- Document A [para 2]: “Lorem [ipsum] dolor sit amet, consectetur adipiscing elit.’,” - \t- *Ut purus est, laoreet non massa id*, *placerat mollis elit*. - ${''} - \t\t- test - ${''} - \t\t- More on this - `); -} - export const obsidianModeTestCases: IntegrationTestCase[] = [ { name: 'Updating YAML in live preview mode does not break YAML and keeps cursor at the expected location', @@ -188,12 +94,10 @@ export const obsidianModeTestCases: IntegrationTestCase[] = [ edgeCaseSetup(plugin, editor), await setWorkspaceItemMode(plugin.app, false); }, - assertions: edgeCaseAssertions, }, { name: 'Updating YAML in source mode does not break YAML when an update is being made to the end of the frontmatter', filePath: 'obsidian-mode/edge-case-yaml.md', setup: edgeCaseSetup, - assertions: edgeCaseAssertions, }, ]; diff --git a/__integration__/yaml-rule.test.ts b/__integration__/yaml-rule.test.ts index ee586af4..0a10b5b2 100644 --- a/__integration__/yaml-rule.test.ts +++ b/__integration__/yaml-rule.test.ts @@ -1,7 +1,5 @@ -import dedent from 'ts-dedent'; import TestLinterPlugin, {IntegrationTestCase} from './main.test'; import {Editor} from 'obsidian'; -import expect from 'expect'; function addBlankLineAfterSetup(plugin: TestLinterPlugin, _editor: Editor) { plugin.plugin.settings.ruleConfigs['add-blank-line-after-yaml'] = { @@ -14,27 +12,10 @@ export const obsidianYAMLRuleTestCases: IntegrationTestCase[] = [ name: 'Updating a file with no yaml for adding blank lines after yaml should do nothing', filePath: 'yaml-rules/add-blank-line-after-yaml/no-yaml.md', setup: addBlankLineAfterSetup, - assertions: (editor: Editor) =>{ - expect(editor.getValue()).toBe(dedent` - This is a file with no YAML in it. - It remains the same, right? - ${''} - `); - }, }, { name: 'Updating a file with yaml and no blanks for adding blank lines after yaml should get updated', filePath: 'yaml-rules/add-blank-line-after-yaml/yaml.md', setup: addBlankLineAfterSetup, - assertions: (editor: Editor) =>{ - expect(editor.getValue()).toBe(dedent` - --- - key: value - --- - ${''} - No blank - ${''} - `); - }, }, ]; diff --git a/test-vault/custom-commands/table-format.linted.md b/test-vault/custom-commands/table-format.linted.md new file mode 100644 index 00000000..90ad6fce --- /dev/null +++ b/test-vault/custom-commands/table-format.linted.md @@ -0,0 +1,23 @@ +| one | two | three | four | +| ----- | --- | ----- | ------------- | +| 1 | ✓ | | | +| 2 | | ✓ | | +| 3 | | ✓ | ✓ | +| 4 | … | | someting else | +| Total | 100 | 20 | 300000000 | + +| one | two | three | four | +| ----- | --- | ----- | ------------- | +| 1 | ✓ | | | +| 2 | | ✓ | | +| 3 | | ✓ | ✓ | +| 4 | … | | someting else | +| Total | 100 | 20 | 300000000 | + +| one | two | three | four | +| ----- | --- | ----- | ------------- | +| 1 | ✓ | | | +| 2 | | ✓ | | +| 3 | | ✓ | ✓ | +| 4 | … | | someting else | +| Total | 100 | 20 | 300000000 | diff --git a/test-vault/obsidian-mode/edge-case-yaml.linted.md b/test-vault/obsidian-mode/edge-case-yaml.linted.md new file mode 100644 index 00000000..f5b26668 --- /dev/null +++ b/test-vault/obsidian-mode/edge-case-yaml.linted.md @@ -0,0 +1,55 @@ +--- +aliases: + - test +tags: + - test1 + - test2 +related: + - "[[test]]" + - "[[test 2]]" +date: 2024-05-22 +class: "[[test]]" +instructor: "[[test]]" +readings: + - "[[test]]" + - "[[test 2#1.1 test chapter]]" + +created: ${moment().format('YYYY-MM-DD')} +last_modified: ${moment().format('YYYY-MM-DD')} +--- + +- Focus on XYZ. + +# I. Test: + +## (Document A, paras [para 2] – [para 8], [para 13] – [para 24]; Document B, para. [3]) + +### a. test (*Document A, para. [para 2])*? + +Lorem ipsum dolor: + +- **test**: **X** v. **Y** *(the allies)* with support from **Y** + + - Lorem ipsum dolor sit amet + consectetur adipiscing elit. Morbi vel ipsum ipsum +- More info ([test](https://www.example.org)): + + - „quote […] quote.” + + - “quote.” + + - “quote.” + +- **test**: X v Y + +- **test:** X v Y + +- (Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel ipsum ipsum.) + +- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel ipsum ipsum. (Document A, para. [2])? + + - Document A [para 2]: “Lorem [ipsum] dolor sit amet, consectetur adipiscing elit.’,” + - *Ut purus est, laoreet non massa id*, *placerat mollis elit*. + + - test + + - More on this \ No newline at end of file diff --git a/test-vault/obsidian-mode/mode-yaml.linted.md b/test-vault/obsidian-mode/mode-yaml.linted.md new file mode 100644 index 00000000..4444fa09 --- /dev/null +++ b/test-vault/obsidian-mode/mode-yaml.linted.md @@ -0,0 +1,27 @@ +--- +author: +- Somebody +citation: unknown +cover: https:github.com +datePub: 1993 +device: +- dsi +format: +- epub +priority: 2 +publisher: Pokemon Publisher +readingStatus: easy +related: +researchArea: +- scifi +status: +summary: +tags: +- pokemon +- monsters +title: Pokemon +total: 481 +withProject: +--- +# Heading here... +Some text here... diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.linted.md b/test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.linted.md new file mode 100644 index 00000000..8ae80a3a --- /dev/null +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/no-yaml.linted.md @@ -0,0 +1,2 @@ +This is a file with no YAML in it. +It remains the same, right? diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.linted.md b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.linted.md new file mode 100644 index 00000000..4e59e263 --- /dev/null +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml-blanks.linted.md @@ -0,0 +1,7 @@ +--- +key: value +--- + + + +No blank \ No newline at end of file diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md new file mode 100644 index 00000000..2aed0838 --- /dev/null +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md @@ -0,0 +1,4 @@ +--- +key: value +--- +No blank From 389f135048f5ea4c6bb25e2629a5f39569fe0809 Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Wed, 21 Aug 2024 22:23:40 -0400 Subject: [PATCH 3/9] fixed up some issues with the linted files not being formatted correctly and started work on getting them all handled corectly, but there is a race condition --- __integration__/main.test.ts | 23 +++++++----- __integration__/obsidian-mode.test.ts | 11 ++++++ .../custom-commands/table-format.linted.md | 36 +++++++++---------- .../obsidian-mode/edge-case-yaml.linted.md | 4 +-- test-vault/obsidian-mode/mode-yaml.linted.md | 21 +++++------ .../add-blank-line-after-yaml/yaml.linted.md | 1 + 6 files changed, 58 insertions(+), 38 deletions(-) diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index 3cd03366..93a2b071 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -11,6 +11,7 @@ export type IntegrationTestCase = { filePath: string, setup?: (plugin: TestLinterPlugin, editor: Editor) => void, assertions?: (editor: Editor) => void, + modifyExpected? (expectedText: string): string, } const testTimeout = 15000; @@ -84,10 +85,7 @@ export default class TestLinterPlugin extends Plugin { } await this.plugin.runLinterEditor(activeLeaf.editor); - expect(activeLeaf.editor).toBe(await this.getExpectedContents(t.filePath.replace('.md', '.linted.md'))); - if (t.assertions) { - await t.assertions(activeLeaf.editor); - } + await this.handleAssertions(t, activeLeaf); console.log('✅', t.name); this.testsCompleted++; @@ -123,10 +121,7 @@ export default class TestLinterPlugin extends Plugin { const t = tests[index]; try { - expect(activeLeaf.editor).toBe(await this.getExpectedContents(t.filePath.replace('.md', '.linted.md'))); - if (t.assertions) { - await t.assertions(activeLeaf.editor); - } + await this.handleAssertions(t, activeLeaf); console.log('✅', t.name); this.testsCompleted++; @@ -185,6 +180,18 @@ export default class TestLinterPlugin extends Plugin { } } + private async handleAssertions(t: IntegrationTestCase, activeLeaf: MarkdownView) { + let expectedText = await this.getExpectedContents(t.filePath.replace('.md', '.linted.md')); + if (t.modifyExpected) { + expectedText = t.modifyExpected(expectedText); + } + + expect(activeLeaf.editor.getValue()).toBe(expectedText); + if (t.assertions) { + await t.assertions(activeLeaf.editor); + } + } + private async resetFileContents(activeLeaf: MarkdownView, originalText: string) { if (activeLeaf) { activeLeaf.editor.setValue(originalText); diff --git a/__integration__/obsidian-mode.test.ts b/__integration__/obsidian-mode.test.ts index c6820c7c..094e01ac 100644 --- a/__integration__/obsidian-mode.test.ts +++ b/__integration__/obsidian-mode.test.ts @@ -2,6 +2,7 @@ import TestLinterPlugin, {IntegrationTestCase} from './main.test'; import {Editor} from 'obsidian'; import expect from 'expect'; import {setWorkspaceItemMode} from './utils.test'; +import moment from 'moment'; const cursorStart = 319; @@ -21,6 +22,14 @@ function modeAssertions(editor: Editor) { expect(editor.posToOffset(editor.getCursor())).toBe(cursorStart+1); } +function edgeCaseExpectedTextModifications(text: string):string { + text = text.replace('{{created_date}}', moment().format('YYYY-MM-DD')); + text = text.replace('{{modified_date}}', moment().format('YYYY-MM-DD')); + + return text; +} + + function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor) { plugin.plugin.settings.ruleConfigs['yaml-timestamp'] = { 'enabled': true, @@ -94,10 +103,12 @@ export const obsidianModeTestCases: IntegrationTestCase[] = [ edgeCaseSetup(plugin, editor), await setWorkspaceItemMode(plugin.app, false); }, + modifyExpected: edgeCaseExpectedTextModifications, }, { name: 'Updating YAML in source mode does not break YAML when an update is being made to the end of the frontmatter', filePath: 'obsidian-mode/edge-case-yaml.md', setup: edgeCaseSetup, + modifyExpected: edgeCaseExpectedTextModifications, }, ]; diff --git a/test-vault/custom-commands/table-format.linted.md b/test-vault/custom-commands/table-format.linted.md index 90ad6fce..0efa9e06 100644 --- a/test-vault/custom-commands/table-format.linted.md +++ b/test-vault/custom-commands/table-format.linted.md @@ -1,23 +1,23 @@ -| one | two | three | four | +| one | two | three | four | | ----- | --- | ----- | ------------- | -| 1 | ✓ | | | -| 2 | | ✓ | | -| 3 | | ✓ | ✓ | -| 4 | … | | someting else | -| Total | 100 | 20 | 300000000 | +| 1 | ✓ | | | +| 2 | | ✓ | | +| 3 | | ✓ | ✓ | +| 4 | … | | someting else | +| Total | 100 | 20 | 300000000 | -| one | two | three | four | +| one | two | three | four | | ----- | --- | ----- | ------------- | -| 1 | ✓ | | | -| 2 | | ✓ | | -| 3 | | ✓ | ✓ | -| 4 | … | | someting else | -| Total | 100 | 20 | 300000000 | +| 1 | ✓ | | | +| 2 | | ✓ | | +| 3 | | ✓ | ✓ | +| 4 | … | | someting else | +| Total | 100 | 20 | 300000000 | -| one | two | three | four | +| one | two | three | four | | ----- | --- | ----- | ------------- | -| 1 | ✓ | | | -| 2 | | ✓ | | -| 3 | | ✓ | ✓ | -| 4 | … | | someting else | -| Total | 100 | 20 | 300000000 | +| 1 | ✓ | | | +| 2 | | ✓ | | +| 3 | | ✓ | ✓ | +| 4 | … | | someting else | +| Total | 100 | 20 | 300000000 | diff --git a/test-vault/obsidian-mode/edge-case-yaml.linted.md b/test-vault/obsidian-mode/edge-case-yaml.linted.md index f5b26668..7570d965 100644 --- a/test-vault/obsidian-mode/edge-case-yaml.linted.md +++ b/test-vault/obsidian-mode/edge-case-yaml.linted.md @@ -14,8 +14,8 @@ readings: - "[[test]]" - "[[test 2#1.1 test chapter]]" -created: ${moment().format('YYYY-MM-DD')} -last_modified: ${moment().format('YYYY-MM-DD')} +created: {{created_date}} +last_modified: {{modified_date}} --- - Focus on XYZ. diff --git a/test-vault/obsidian-mode/mode-yaml.linted.md b/test-vault/obsidian-mode/mode-yaml.linted.md index 4444fa09..7262ae1f 100644 --- a/test-vault/obsidian-mode/mode-yaml.linted.md +++ b/test-vault/obsidian-mode/mode-yaml.linted.md @@ -1,27 +1,28 @@ --- author: -- Somebody + - Somebody citation: unknown cover: https:github.com datePub: 1993 device: -- dsi + - dsi format: -- epub + - epub priority: 2 publisher: Pokemon Publisher readingStatus: easy -related: +related: researchArea: -- scifi -status: -summary: + - scifi +status: +summary: tags: -- pokemon -- monsters + - pokemon + - monsters title: Pokemon total: 481 -withProject: +withProject: --- # Heading here... + Some text here... diff --git a/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md index 2aed0838..91de99ec 100644 --- a/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md +++ b/test-vault/yaml-rules/add-blank-line-after-yaml/yaml.linted.md @@ -1,4 +1,5 @@ --- key: value --- + No blank From d4ce97184f68024503f34e74f9c92b0a05960381 Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Wed, 21 Aug 2024 22:52:34 -0400 Subject: [PATCH 4/9] got several more things fixed, but still have the race condition in place where assertions are not completing before the next test starts running --- .eslintrc.js | 2 + __integration__/main.test.ts | 16 ++++---- package-lock.json | 41 ++++++++++++++++++- package.json | 8 ++-- src/main.ts | 24 +++++------ src/option.ts | 12 +++--- src/ui/components/dropdown-setting.ts | 2 +- src/ui/components/number-input-setting.ts | 2 +- src/ui/components/toggle-setting.ts | 2 +- src/ui/helpers.ts | 2 +- .../tab-components/custom-tab.ts | 4 +- .../tab-components/general-tab.ts | 4 +- src/ui/suggesters/suggest.ts | 2 +- 13 files changed, 81 insertions(+), 40 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cd3cbd4a..3bab8359 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,6 +12,7 @@ module.exports = { 'parserOptions': { 'ecmaVersion': 12, 'sourceType': 'module', + 'project': ['./tsconfig.json', './packages/*/tsconfig.json'], }, 'plugins': [ '@typescript-eslint', @@ -29,6 +30,7 @@ module.exports = { 'require-jsdoc': 'off', 'unicorn/template-indent': 'error', 'no-unused-vars': 'off', + '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-unused-vars': [ 'error', { diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index 93a2b071..7bd5f0d4 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -21,8 +21,7 @@ export default class TestLinterPlugin extends Plugin { afterCacheUpdateTests: Array = [...customCommandTestCases]; plugin: LinterPlugin; private testsCompleted: number; - // eslint-disable-next-line no-undef - private timeoutId: Timeout = undefined; + private timeoutId: any = undefined; async onload() { this.addCommand({ @@ -81,7 +80,7 @@ export default class TestLinterPlugin extends Plugin { try { if (t.setup) { - await t.setup(this, activeLeaf.editor); + t.setup(this, activeLeaf.editor); } await this.plugin.runLinterEditor(activeLeaf.editor); @@ -95,6 +94,7 @@ export default class TestLinterPlugin extends Plugin { this.testsCompleted++; } + console.log('resetting file contents for ' + t.filePath); await this.resetFileContents(activeLeaf, originalText); } @@ -158,7 +158,7 @@ export default class TestLinterPlugin extends Plugin { try { if (t.setup) { - await t.setup(this, activeLeaf.editor); + t.setup(this, activeLeaf.editor); } await testPlugin.plugin.runLinterEditor(activeLeaf.editor); @@ -174,9 +174,9 @@ export default class TestLinterPlugin extends Plugin { return originalText; } - onunload(): void { + async onunload(): Promise { if (this.plugin) { - this.plugin.onunload(); + await this.plugin.onunload(); } } @@ -188,8 +188,10 @@ export default class TestLinterPlugin extends Plugin { expect(activeLeaf.editor.getValue()).toBe(expectedText); if (t.assertions) { - await t.assertions(activeLeaf.editor); + t.assertions(activeLeaf.editor); } + + console.log('assertions complete for ' + t.filePath); } private async resetFileContents(activeLeaf: MarkdownView, originalText: string) { diff --git a/package-lock.json b/package-lock.json index a6d53a96..de4eac5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-linter", - "version": "1.26.0-rc-2", + "version": "1.26.0-rc-3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-linter", - "version": "1.26.0-rc-2", + "version": "1.26.0-rc-3", "license": "MIT", "dependencies": { "@popperjs/core": "^2.11.6", @@ -52,6 +52,7 @@ "eslint": "^8.57.0", "eslint-config-google": "^0.14.0", "eslint-plugin-jest": "^27.9.0", + "eslint-plugin-no-floating-promise": "^2.0.0", "eslint-plugin-unicorn": "^51.0.1", "jest": "^29.3.1", "moment": "^2.30.1", @@ -5282,6 +5283,18 @@ } } }, + "node_modules/eslint-plugin-no-floating-promise": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-floating-promise/-/eslint-plugin-no-floating-promise-2.0.0.tgz", + "integrity": "sha512-XVAk+a1Qq3fsfY8tLT64Ky4sdJjZSjx0BsDxjdWbyceU0yWwg1ZKHiWgaOZ0hDYNzrl3qx5MEGrRlTceGzd0ow==", + "dev": true, + "dependencies": { + "requireindex": "1.2.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/eslint-plugin-unicorn": { "version": "51.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-51.0.1.tgz", @@ -9433,6 +9446,15 @@ "node": ">=0.10.0" } }, + "node_modules/requireindex": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", + "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", + "dev": true, + "engines": { + "node": ">=0.10.5" + } + }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -14185,6 +14207,15 @@ "@typescript-eslint/utils": "^5.10.0" } }, + "eslint-plugin-no-floating-promise": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-floating-promise/-/eslint-plugin-no-floating-promise-2.0.0.tgz", + "integrity": "sha512-XVAk+a1Qq3fsfY8tLT64Ky4sdJjZSjx0BsDxjdWbyceU0yWwg1ZKHiWgaOZ0hDYNzrl3qx5MEGrRlTceGzd0ow==", + "dev": true, + "requires": { + "requireindex": "1.2.0" + } + }, "eslint-plugin-unicorn": { "version": "51.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-51.0.1.tgz", @@ -17031,6 +17062,12 @@ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true }, + "requireindex": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", + "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", + "dev": true + }, "resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", diff --git a/package.json b/package.json index 7faf72fd..1bd9cc7f 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@babel/core": "^7.24.0", "@babel/plugin-proposal-decorators": "^7.24.0", "@babel/plugin-transform-class-properties": "^7.23.3", + "@babel/plugin-transform-private-methods": "^7.23.3", "@babel/preset-env": "^7.24.0", "@babel/preset-typescript": "^7.18.6", "@jest/types": "^29.5.0", @@ -28,6 +29,7 @@ "@types/diff": "^5.0.9", "@types/diff-match-patch": "^1.0.32", "@types/jest": "^29.5.12", + "@types/js-yaml": "^4.0.5", "@types/node": "^20.11.28", "@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/parser": "^7.2.0", @@ -47,13 +49,11 @@ "ts-node": "^10.9.2", "tslib": "^2.4.1", "typescript": "^5.4.2", - "unified-lint-rule": "^2.1.1", - "@babel/plugin-transform-private-methods": "^7.23.3", - "@types/js-yaml": "^4.0.5" + "unified-lint-rule": "^2.1.1" }, "dependencies": { - "async-lock": "^1.4.1", "@popperjs/core": "^2.11.6", + "async-lock": "^1.4.1", "diff-match-patch": "^1.0.5", "js-yaml": "^4.1.0", "loglevel": "^1.9.1", diff --git a/src/main.ts b/src/main.ts index 07c2a558..ec27c15a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -115,7 +115,7 @@ export default class LinterPlugin extends Plugin { } setLogLevel(this.settings.logLevel); - this.setOrUpdateMomentInstance(); + await this.setOrUpdateMomentInstance(); if (!this.settings.settingsConvertedToConfigKeyValues) { this.moveConfigValuesToKeyBasedFormat(); @@ -160,7 +160,7 @@ export default class LinterPlugin extends Plugin { return that.isMarkdownFile(ctx.file); } - that.runLinterEditor(editor); + void that.runLinterEditor(editor); }, icon: iconInfo.file.id, hotkeys: [ @@ -180,7 +180,7 @@ export default class LinterPlugin extends Plugin { } if (!that.shouldIgnoreFile(ctx.file)) { - that.runLinterEditor(editor); + void that.runLinterEditor(editor); } }, icon: iconInfo.file.id, @@ -221,7 +221,7 @@ export default class LinterPlugin extends Plugin { return this.overridePaste; } - this.pasteAsPlainText(editor); + void this.pasteAsPlainText(editor); }, }); } @@ -235,7 +235,7 @@ export default class LinterPlugin extends Plugin { return; } - this.modifyPasteEvent(clipboardEv); + void this.modifyPasteEvent(clipboardEv); }); this.registerEvent(eventRef); this.eventRefs.push(eventRef); @@ -270,7 +270,7 @@ export default class LinterPlugin extends Plugin { if (editor) { const file = this.app.workspace.getActiveFile(); if (!this.shouldIgnoreFile(file) && this.isMarkdownFile(file)) { - this.runLinterEditor(editor); + void this.runLinterEditor(editor); } } } @@ -289,11 +289,11 @@ export default class LinterPlugin extends Plugin { if (this.editorLintFiles.includes(file)) { this.editorLintFiles.remove(file); - this.runCustomCommands(file); + void this.runCustomCommands(file); } else if (this.fileLintFiles.has(file)) { this.fileLintFiles.delete(file); - this.runCustomCommandsInSidebar(file); + void this.runCustomCommandsInSidebar(file); } } @@ -306,9 +306,9 @@ export default class LinterPlugin extends Plugin { const activeFile = this.app.workspace.getActiveFile(); const editor = this.getEditor(); if (activeFile === file && editor) { - this.runLinterEditor(editor); + void this.runLinterEditor(editor); } else { - this.runLinterFile(file); + void this.runLinterFile(file); } }); }); @@ -545,7 +545,7 @@ export default class LinterPlugin extends Plugin { // run custom commands now since no change was made if (!charsAdded && !charsRemoved) { - this.runCustomCommands(file); + void this.runCustomCommands(file); } else { this.editorLintFiles.push(file); } @@ -837,7 +837,7 @@ export default class LinterPlugin extends Plugin { } this.settings.settingsConvertedToConfigKeyValues = true; - this.saveSettings(); + void this.saveSettings(); setLanguage(window.localStorage.getItem('language')); } diff --git a/src/option.ts b/src/option.ts index 9065a31b..de8dbfae 100644 --- a/src/option.ts +++ b/src/option.ts @@ -61,7 +61,7 @@ export class BooleanOption extends Option { toggle.onChange((value) => { this.setOption(value, settings); plugin.settings = settings; - plugin.saveSettings(); + void plugin.saveSettings(); }); }); @@ -79,7 +79,7 @@ export class TextOption extends Option { textbox.onChange((value) => { this.setOption(value, settings); plugin.settings = settings; - plugin.saveSettings(); + void plugin.saveSettings(); }); }); @@ -97,7 +97,7 @@ export class TextAreaOption extends Option { textbox.onChange((value) => { this.setOption(value, settings); plugin.settings = settings; - plugin.saveSettings(); + void plugin.saveSettings(); }); }); @@ -116,7 +116,7 @@ export class MomentFormatOption extends Option { format.onChange((value) => { this.setOption(value, settings); plugin.settings = settings; - plugin.saveSettings(); + void plugin.saveSettings(); }); }); @@ -165,7 +165,7 @@ export class DropdownOption extends Option { dropdown.onChange((value) => { this.setOption(value, settings); plugin.settings = settings; - plugin.saveSettings(); + void plugin.saveSettings(); }); }); @@ -183,7 +183,7 @@ export class MdFilePickerOption extends Option { settings.ruleConfigs[this.ruleAlias][this.configKey] = settings.ruleConfigs[this.ruleAlias][this.configKey] ?? []; new AutoCorrectFilesPickerOption(containerEl, plugin.settingsTab.component, settings.ruleConfigs[this.ruleAlias][this.configKey], plugin.app, () => { - plugin.saveSettings(); + void plugin.saveSettings(); }, this.nameKey, this.descriptionKey); } } diff --git a/src/ui/components/dropdown-setting.ts b/src/ui/components/dropdown-setting.ts index 80a3a550..40c44f3b 100644 --- a/src/ui/components/dropdown-setting.ts +++ b/src/ui/components/dropdown-setting.ts @@ -26,7 +26,7 @@ export class DropdownSetting extends BaseSetting { dropdown.setValue(this.getString()); dropdown.onChange(async (value) => { - this.saveValue(value); + void this.saveValue(value); }); }); } diff --git a/src/ui/components/number-input-setting.ts b/src/ui/components/number-input-setting.ts index 79b96b71..267815eb 100644 --- a/src/ui/components/number-input-setting.ts +++ b/src/ui/components/number-input-setting.ts @@ -20,7 +20,7 @@ export class NumberInputSetting extends BaseSetting { textbox .setValue(this.getNumber().toString()) .onChange(async (value) => { - this.saveValue(parseInt(value)); + void this.saveValue(parseInt(value)); }); }); } diff --git a/src/ui/components/toggle-setting.ts b/src/ui/components/toggle-setting.ts index 4673ad2e..a2e3b438 100644 --- a/src/ui/components/toggle-setting.ts +++ b/src/ui/components/toggle-setting.ts @@ -16,7 +16,7 @@ export class ToggleSetting extends BaseSetting { toggle .setValue(this.getBoolean()) .onChange(async (value) => { - this.saveValue(value); + void this.saveValue(value); }); }); diff --git a/src/ui/helpers.ts b/src/ui/helpers.ts index cd27e960..b95f34eb 100644 --- a/src/ui/helpers.ts +++ b/src/ui/helpers.ts @@ -1,7 +1,7 @@ import {Component, MarkdownRenderer} from 'obsidian'; export function parseTextToHTMLWithoutOuterParagraph(text: string, containerEl: HTMLElement, component: Component) { - MarkdownRenderer.renderMarkdown(text, containerEl, '', component); + void MarkdownRenderer.renderMarkdown(text, containerEl, '', component); let htmlString = containerEl.innerHTML.trim(); if (htmlString.startsWith('

')) { diff --git a/src/ui/linter-components/tab-components/custom-tab.ts b/src/ui/linter-components/tab-components/custom-tab.ts index bb760e62..8569c5d8 100644 --- a/src/ui/linter-components/tab-components/custom-tab.ts +++ b/src/ui/linter-components/tab-components/custom-tab.ts @@ -13,13 +13,13 @@ export class CustomTab extends Tab { display(): void { const customCommandEl = this.contentEl.createDiv(); const customCommands = new CustomCommandOption(customCommandEl, this.plugin.settingsTab.component, this.plugin.settings.lintCommands, this.app, () => { - this.plugin.saveSettings(); + void this.plugin.saveSettings(); }); this.addSettingSearchInfo(customCommandEl, customCommands.name, customCommands.description.replaceAll('\n', ' ') + customCommands.warning.replaceAll('\n', ' ')); const customReplaceEl = this.contentEl.createDiv(); const customRegexes = new CustomReplaceOption(customReplaceEl, this.plugin.settingsTab.component, this.plugin.settings.customRegexes, () => { - this.plugin.saveSettings(); + void this.plugin.saveSettings(); }); this.addSettingSearchInfo(customReplaceEl, customRegexes.name, customRegexes.description.replaceAll('\n', ' ') + customRegexes.warning.replaceAll('\n', ' ')); } diff --git a/src/ui/linter-components/tab-components/general-tab.ts b/src/ui/linter-components/tab-components/general-tab.ts index 679702f7..0e80e0db 100644 --- a/src/ui/linter-components/tab-components/general-tab.ts +++ b/src/ui/linter-components/tab-components/general-tab.ts @@ -98,14 +98,14 @@ export class GeneralTab extends Tab { const folderIgnoreEl = this.contentEl.createDiv(); const folderIgnore = new FolderIgnoreOption(folderIgnoreEl, this.plugin.settingsTab.component, this.plugin.settings.foldersToIgnore, this.app, () => { - this.plugin.saveSettings(); + void this.plugin.saveSettings(); }); this.addSettingSearchInfo(folderIgnoreEl, folderIgnore.name, folderIgnore.description.replaceAll('\n', ' ')); const filesToIgnoreEl = this.contentEl.createDiv(); const filesToIgnore = new FilesToIgnoreOption(filesToIgnoreEl, this.plugin.settingsTab.component, this.plugin.settings.filesToIgnore, () => { - this.plugin.saveSettings(); + void this.plugin.saveSettings(); }); this.addSettingSearchInfo(filesToIgnoreEl, filesToIgnore.name, filesToIgnore.description.replaceAll('\n', ' ')); diff --git a/src/ui/suggesters/suggest.ts b/src/ui/suggesters/suggest.ts index 9d7e500f..b625294b 100644 --- a/src/ui/suggesters/suggest.ts +++ b/src/ui/suggesters/suggest.ts @@ -179,7 +179,7 @@ export abstract class TextInputSuggest implements ISuggestOwner { return; } state.styles.popper.width = targetWidth; - instance.update(); + void instance.update(); }, phase: 'beforeWrite', requires: ['computeStyles'], From 628b0e74621d401e94fc6cffbe1152240beb0997 Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Thu, 22 Aug 2024 08:26:28 -0400 Subject: [PATCH 5/9] fixed an issue with the callback for the Linter not getting removed after all custom commands ran --- __integration__/main.test.ts | 32 ++++++++++++------- __integration__/obsidian-mode.test.ts | 12 ++++--- __integration__/yaml-rule.test.ts | 4 ++- .../obsidian-mode/edge-case-yaml.linted.md | 2 +- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index 7bd5f0d4..d3b909fc 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -1,4 +1,4 @@ -import {Editor, MarkdownView, Plugin, TFile, normalizePath} from 'obsidian'; +import {Editor, MarkdownView, Notice, Plugin, TFile, normalizePath} from 'obsidian'; import LinterPlugin from 'src/main'; import {obsidianModeTestCases} from './obsidian-mode.test'; import {setWorkspaceItemMode} from './utils.test'; @@ -9,9 +9,9 @@ import expect from 'expect'; export type IntegrationTestCase = { name: string, filePath: string, - setup?: (plugin: TestLinterPlugin, editor: Editor) => void, + setup?: (plugin: TestLinterPlugin, editor: Editor) => Promise, assertions?: (editor: Editor) => void, - modifyExpected? (expectedText: string): string, + modifyExpected?: (expectedText: string) => string, } const testTimeout = 15000; @@ -22,6 +22,7 @@ export default class TestLinterPlugin extends Plugin { plugin: LinterPlugin; private testsCompleted: number; private timeoutId: any = undefined; + private testRunNotice: Notice; async onload() { this.addCommand({ @@ -61,6 +62,8 @@ export default class TestLinterPlugin extends Plugin { } async runTests() { + this.testRunNotice = new Notice('Starting the Linter\'s Integration Tests', 0); + const activeLeaf = this.getActiveLeaf(); if (!activeLeaf) { console.error('failed to get active leaf'); @@ -80,7 +83,7 @@ export default class TestLinterPlugin extends Plugin { try { if (t.setup) { - t.setup(this, activeLeaf.editor); + await t.setup(this, activeLeaf.editor); } await this.plugin.runLinterEditor(activeLeaf.editor); @@ -94,10 +97,14 @@ export default class TestLinterPlugin extends Plugin { this.testsCompleted++; } - console.log('resetting file contents for ' + t.filePath); await this.resetFileContents(activeLeaf, originalText); } + if (this.testsCompleted != this.regularTests.length) { + console.log(`❌ failed to run all ${this.regularTests.length} regular tests before attempting to start the metadata tests.`); + return; + } + await this.runMetadataTests(this.afterCacheUpdateTests, activeLeaf); } @@ -134,12 +141,9 @@ export default class TestLinterPlugin extends Plugin { await that.resetFileContents(activeLeaf, originalText); originalText = null; - while (index+1 < tests.length && originalText == null) { + if (index+1 < tests.length) { originalText = await that.setupMetadataTest(that, tests[++index], activeLeaf); - } - - // remove the custom commands callback once all tests have run - if (index >= tests.length && originalText == null) { + } else { // remove the custom commands callback once all tests have run that.plugin.setCustomCommandCallback(null); } }); @@ -158,7 +162,7 @@ export default class TestLinterPlugin extends Plugin { try { if (t.setup) { - t.setup(this, activeLeaf.editor); + await t.setup(this, activeLeaf.editor); } await testPlugin.plugin.runLinterEditor(activeLeaf.editor); @@ -192,6 +196,8 @@ export default class TestLinterPlugin extends Plugin { } console.log('assertions complete for ' + t.filePath); + + return; } private async resetFileContents(activeLeaf: MarkdownView, originalText: string) { @@ -229,4 +235,8 @@ export default class TestLinterPlugin extends Plugin { private async resetSettings() { await this.plugin.loadSettings(); } + + // private updateNoticeText() { + + // } } diff --git a/__integration__/obsidian-mode.test.ts b/__integration__/obsidian-mode.test.ts index 094e01ac..1ab42f3e 100644 --- a/__integration__/obsidian-mode.test.ts +++ b/__integration__/obsidian-mode.test.ts @@ -6,7 +6,7 @@ import moment from 'moment'; const cursorStart = 319; -function modeSetup(plugin: TestLinterPlugin, editor: Editor) { +function modeSetup(plugin: TestLinterPlugin, editor: Editor): Promise { plugin.plugin.settings.ruleConfigs['yaml-key-sort'] = { 'enabled': true, 'yaml-key-priority-sort-order': '', @@ -15,6 +15,8 @@ function modeSetup(plugin: TestLinterPlugin, editor: Editor) { }; editor.setCursor(editor.offsetToPos(cursorStart)); + + return; } function modeAssertions(editor: Editor) { @@ -30,7 +32,7 @@ function edgeCaseExpectedTextModifications(text: string):string { } -function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor) { +function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor): Promise { plugin.plugin.settings.ruleConfigs['yaml-timestamp'] = { 'enabled': true, 'date-created': true, @@ -78,6 +80,8 @@ function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor) { 'enabled': true, 'style': 'asterisk', }; + + return; } export const obsidianModeTestCases: IntegrationTestCase[] = [ @@ -85,7 +89,7 @@ export const obsidianModeTestCases: IntegrationTestCase[] = [ name: 'Updating YAML in live preview mode does not break YAML and keeps cursor at the expected location', filePath: 'obsidian-mode/mode-yaml.md', async setup(plugin: TestLinterPlugin, editor: Editor) { - modeSetup(plugin, editor), + await modeSetup(plugin, editor), await setWorkspaceItemMode(plugin.app, false); }, assertions: modeAssertions, @@ -100,7 +104,7 @@ export const obsidianModeTestCases: IntegrationTestCase[] = [ name: 'Updating YAML in live preview mode does not break YAML when an update is being made to the end of the frontmatter', filePath: 'obsidian-mode/edge-case-yaml.md', async setup(plugin: TestLinterPlugin, editor: Editor) { - edgeCaseSetup(plugin, editor), + await edgeCaseSetup(plugin, editor), await setWorkspaceItemMode(plugin.app, false); }, modifyExpected: edgeCaseExpectedTextModifications, diff --git a/__integration__/yaml-rule.test.ts b/__integration__/yaml-rule.test.ts index 0a10b5b2..bb5ce586 100644 --- a/__integration__/yaml-rule.test.ts +++ b/__integration__/yaml-rule.test.ts @@ -1,10 +1,12 @@ import TestLinterPlugin, {IntegrationTestCase} from './main.test'; import {Editor} from 'obsidian'; -function addBlankLineAfterSetup(plugin: TestLinterPlugin, _editor: Editor) { +function addBlankLineAfterSetup(plugin: TestLinterPlugin, _: Editor): Promise { plugin.plugin.settings.ruleConfigs['add-blank-line-after-yaml'] = { 'enabled': true, }; + + return; } export const obsidianYAMLRuleTestCases: IntegrationTestCase[] = [ diff --git a/test-vault/obsidian-mode/edge-case-yaml.linted.md b/test-vault/obsidian-mode/edge-case-yaml.linted.md index 7570d965..cacc78a0 100644 --- a/test-vault/obsidian-mode/edge-case-yaml.linted.md +++ b/test-vault/obsidian-mode/edge-case-yaml.linted.md @@ -14,7 +14,7 @@ readings: - "[[test]]" - "[[test 2#1.1 test chapter]]" -created: {{created_date}} +created: 2024-08-21 last_modified: {{modified_date}} --- From 28f139c37691a25d945f4e8faa112bfae9e4c3ed Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Fri, 13 Sep 2024 17:40:11 -0400 Subject: [PATCH 6/9] stash commit with some changes to better resemble updating a notice for the user --- __integration__/main.test.ts | 135 ++++++++++++++++++++++++++++++----- 1 file changed, 116 insertions(+), 19 deletions(-) diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index d3b909fc..c2b0a92a 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -14,6 +14,11 @@ export type IntegrationTestCase = { modifyExpected?: (expectedText: string) => string, } +type testStatus = { + name: string, + succeeded: boolean, +} + const testTimeout = 15000; export default class TestLinterPlugin extends Plugin { @@ -35,16 +40,18 @@ export default class TestLinterPlugin extends Plugin { await this.setup(); - this.timeoutId = setTimeout(() =>{ - const expectedTestCount = this.regularTests.length + this.afterCacheUpdateTests.length; - if (this.testsCompleted != expectedTestCount) { - console.log('❌', `Tests took too long to run with only ${this.testsCompleted} of ${expectedTestCount} tests running in ${testTimeout/1000}s.`); + const testStatuses = [] as testStatus[]; + const expectedTestCount = this.regularTests.length + this.afterCacheUpdateTests.length; + this.timeoutId = setTimeout(() => { + console.log(testStatuses); + if (testStatuses.length != expectedTestCount) { + console.log('❌', `Tests took too long to run with only ${testStatuses.length} of ${expectedTestCount} tests running in ${testTimeout/1000}s.`); } else { console.log(`✅ all ${expectedTestCount} tests have completed in the alloted time.`); } }, testTimeout); - await this.runTests(); + await this.runTests(testStatuses, expectedTestCount); }, }); } @@ -61,7 +68,7 @@ export default class TestLinterPlugin extends Plugin { this.testsCompleted = 0; } - async runTests() { + async runTests(testStatuses: testStatus[], totalTestCount: number) { this.testRunNotice = new Notice('Starting the Linter\'s Integration Tests', 0); const activeLeaf = this.getActiveLeaf(); @@ -74,6 +81,8 @@ export default class TestLinterPlugin extends Plugin { const file = this.getFileFromPath(t.filePath); if (!file) { console.error('failed to get file: ' + t.filePath); + + this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); continue; } @@ -89,28 +98,30 @@ export default class TestLinterPlugin extends Plugin { await this.plugin.runLinterEditor(activeLeaf.editor); await this.handleAssertions(t, activeLeaf); + this.handleTestCompletion(t.name, true, testStatuses, totalTestCount); console.log('✅', t.name); - this.testsCompleted++; + // this.testsCompleted++; } catch (e) { console.log('❌', t.name); console.error(e); - this.testsCompleted++; + this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); + // this.testsCompleted++; } await this.resetFileContents(activeLeaf, originalText); } - if (this.testsCompleted != this.regularTests.length) { + if (testStatuses.length != this.regularTests.length) { console.log(`❌ failed to run all ${this.regularTests.length} regular tests before attempting to start the metadata tests.`); return; } - await this.runMetadataTests(this.afterCacheUpdateTests, activeLeaf); + await this.runMetadataTests(this.afterCacheUpdateTests, activeLeaf, testStatuses, totalTestCount); } - async runMetadataTests(tests: IntegrationTestCase[], activeLeaf: MarkdownView) { + async runMetadataTests(tests: IntegrationTestCase[], activeLeaf: MarkdownView, testStatuses: testStatus[], totalTestCount: number) { let index = 0; - let originalText = await this.setupMetadataTest(this, tests[index], activeLeaf); + let originalText = await this.setupMetadataTest(this, tests[index], activeLeaf, testStatuses, totalTestCount); if (originalText == null) { return; } @@ -130,26 +141,36 @@ export default class TestLinterPlugin extends Plugin { try { await this.handleAssertions(t, activeLeaf); + this.handleTestCompletion(t.name, true, testStatuses, totalTestCount); + // testStatuses.push({ + // name: t.name, + // succeeded: true, + // }); console.log('✅', t.name); - this.testsCompleted++; + // this.testsCompleted++; } catch (e) { + // testStatuses.push({ + // name: t.name, + // succeeded: false, + // }); + this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); console.log('❌', t.name); console.error(e); - this.testsCompleted++; + // this.testsCompleted++; } await that.resetFileContents(activeLeaf, originalText); originalText = null; if (index+1 < tests.length) { - originalText = await that.setupMetadataTest(that, tests[++index], activeLeaf); + originalText = await that.setupMetadataTest(that, tests[++index], activeLeaf, testStatuses, totalTestCount); } else { // remove the custom commands callback once all tests have run that.plugin.setCustomCommandCallback(null); } }); } - async setupMetadataTest(testPlugin: TestLinterPlugin, t: IntegrationTestCase, activeLeaf: MarkdownView): Promise { + async setupMetadataTest(testPlugin: TestLinterPlugin, t: IntegrationTestCase, activeLeaf: MarkdownView, testStatuses: testStatus[], totalTestCount: number): Promise { const file = this.getFileFromPath(t.filePath); if (!file) { console.error('failed to get file: ' + t.filePath); @@ -167,7 +188,11 @@ export default class TestLinterPlugin extends Plugin { await testPlugin.plugin.runLinterEditor(activeLeaf.editor); } catch (e) { - this.testsCompleted++; + // testStatuses.push({ + // name: t.name, + // succeeded: false, + // }); + this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); console.log('❌', t.name); console.error(e); await testPlugin.resetFileContents(activeLeaf, originalText); @@ -236,7 +261,79 @@ export default class TestLinterPlugin extends Plugin { await this.plugin.loadSettings(); } - // private updateNoticeText() { + private handleTestCompletion(testName: string, succeeded: boolean, testStatuses: testStatus[], totalTestCount: number) { + testStatuses.push( + { + name: testName, + succeeded: succeeded, + }); + + let numberOfSuccesses = 0; + let numberOfFailures = 0; + for (const testResult of testStatuses) { + if (testResult.succeeded) { + numberOfSuccesses++; + } else { + numberOfFailures++; + } + } + + if (this.testRunNotice) { + let message = `Running the Linter's Integration Tests (${testStatuses.length}/${totalTestCount})`; + message += '\nSo far there '; + + if (numberOfFailures == 1) { + message += 'has been 1 failure'; + } else { + message += `have been ${numberOfFailures} failures`; + } + + message += ' and there '; + + if (numberOfSuccesses == 1) { + message += 'has been 1 success'; + } else { + message += `have been ${numberOfSuccesses} successes`; + } + + message += '.'; + + this.testRunNotice.setMessage(message); + } + } + + private handleTestFinalization(testStatuses: testStatus[]) { + if (this.testRunNotice) { + let message = `Finished running the Linter's Integration Tests.`; + message += '\nThere '; + + // if (numberOfFailures == 1) { + // message += 'was 1 failure'; + // } else { + // message += `have been ${numberOfFailures} failures`; + // } - // } + // message += ' and there '; + + // if (numberOfSuccesses == 1) { + // message += 'has been 1 success'; + // } else { + // message += `have been ${numberOfSuccesses} successes`; + // } + + // message += '.'; + + this.testRunNotice.setMessage(message); + } + + // let numberOfSuccesses = 0; + // let numberOfFailures = 0; + // for (const testResult of testStatuses) { + // if (testResult.succeeded) { + // numberOfSuccesses++; + // } else { + // numberOfFailures++; + // } + // } + } } From 8c6ed2a1f85c84fdd274fa33fb9218ae5168cf8c Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Fri, 13 Sep 2024 18:57:49 -0400 Subject: [PATCH 7/9] got new integration setup and more robust with a notice to let the user know the result of the test run --- __integration__/main.test.ts | 95 +++++++++---------- __integration__/obsidian-mode.test.ts | 6 +- .../obsidian-mode/edge-case-yaml.linted.md | 2 +- 3 files changed, 48 insertions(+), 55 deletions(-) diff --git a/__integration__/main.test.ts b/__integration__/main.test.ts index c2b0a92a..05befcbe 100644 --- a/__integration__/main.test.ts +++ b/__integration__/main.test.ts @@ -11,7 +11,7 @@ export type IntegrationTestCase = { filePath: string, setup?: (plugin: TestLinterPlugin, editor: Editor) => Promise, assertions?: (editor: Editor) => void, - modifyExpected?: (expectedText: string) => string, + modifyExpected?: (expectedText: string, file: TFile) => string, } type testStatus = { @@ -25,7 +25,6 @@ export default class TestLinterPlugin extends Plugin { regularTests: Array = [...obsidianModeTestCases, ...obsidianYAMLRuleTestCases]; afterCacheUpdateTests: Array = [...customCommandTestCases]; plugin: LinterPlugin; - private testsCompleted: number; private timeoutId: any = undefined; private testRunNotice: Notice; @@ -45,8 +44,13 @@ export default class TestLinterPlugin extends Plugin { this.timeoutId = setTimeout(() => { console.log(testStatuses); if (testStatuses.length != expectedTestCount) { - console.log('❌', `Tests took too long to run with only ${testStatuses.length} of ${expectedTestCount} tests running in ${testTimeout/1000}s.`); + if (this.testRunNotice) { + this.testRunNotice.setMessage(`❌: Tests took too long to run with only ${testStatuses.length} of ${expectedTestCount} tests running in ${testTimeout/1000}s.`); + } else { + console.log('❌', `Tests took too long to run with only ${testStatuses.length} of ${expectedTestCount} tests running in ${testTimeout/1000}s.`); + } } else { + this.handleTestFinalization(testStatuses); console.log(`✅ all ${expectedTestCount} tests have completed in the alloted time.`); } }, testTimeout); @@ -64,8 +68,6 @@ export default class TestLinterPlugin extends Plugin { } else { await this.resetSettings(); } - - this.testsCompleted = 0; } async runTests(testStatuses: testStatus[], totalTestCount: number) { @@ -96,23 +98,26 @@ export default class TestLinterPlugin extends Plugin { } await this.plugin.runLinterEditor(activeLeaf.editor); - await this.handleAssertions(t, activeLeaf); + await this.handleAssertions(t, activeLeaf, file); - this.handleTestCompletion(t.name, true, testStatuses, totalTestCount); console.log('✅', t.name); - // this.testsCompleted++; + this.handleTestCompletion(t.name, true, testStatuses, totalTestCount); } catch (e) { console.log('❌', t.name); console.error(e); + this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); - // this.testsCompleted++; } await this.resetFileContents(activeLeaf, originalText); } if (testStatuses.length != this.regularTests.length) { - console.log(`❌ failed to run all ${this.regularTests.length} regular tests before attempting to start the metadata tests.`); + if (this.testRunNotice) { + this.testRunNotice.setMessage(`❌ failed to run all ${this.regularTests.length} regular tests before attempting to start the metadata tests.`); + } else { + console.log(`❌ failed to run all ${this.regularTests.length} regular tests before attempting to start the metadata tests.`); + } return; } @@ -139,24 +144,15 @@ export default class TestLinterPlugin extends Plugin { const t = tests[index]; try { - await this.handleAssertions(t, activeLeaf); + await this.handleAssertions(t, activeLeaf, file); - this.handleTestCompletion(t.name, true, testStatuses, totalTestCount); - // testStatuses.push({ - // name: t.name, - // succeeded: true, - // }); console.log('✅', t.name); - // this.testsCompleted++; + this.handleTestCompletion(t.name, true, testStatuses, totalTestCount); } catch (e) { - // testStatuses.push({ - // name: t.name, - // succeeded: false, - // }); - this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); console.log('❌', t.name); console.error(e); - // this.testsCompleted++; + + this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); } await that.resetFileContents(activeLeaf, originalText); @@ -188,11 +184,8 @@ export default class TestLinterPlugin extends Plugin { await testPlugin.plugin.runLinterEditor(activeLeaf.editor); } catch (e) { - // testStatuses.push({ - // name: t.name, - // succeeded: false, - // }); this.handleTestCompletion(t.name, false, testStatuses, totalTestCount); + console.log('❌', t.name); console.error(e); await testPlugin.resetFileContents(activeLeaf, originalText); @@ -209,10 +202,10 @@ export default class TestLinterPlugin extends Plugin { } } - private async handleAssertions(t: IntegrationTestCase, activeLeaf: MarkdownView) { + private async handleAssertions(t: IntegrationTestCase, activeLeaf: MarkdownView, file: TFile) { let expectedText = await this.getExpectedContents(t.filePath.replace('.md', '.linted.md')); if (t.modifyExpected) { - expectedText = t.modifyExpected(expectedText); + expectedText = t.modifyExpected(expectedText, file); } expect(activeLeaf.editor.getValue()).toBe(expectedText); @@ -307,33 +300,33 @@ export default class TestLinterPlugin extends Plugin { let message = `Finished running the Linter's Integration Tests.`; message += '\nThere '; - // if (numberOfFailures == 1) { - // message += 'was 1 failure'; - // } else { - // message += `have been ${numberOfFailures} failures`; - // } + let numberOfSuccesses = 0; + let numberOfFailures = 0; + for (const testResult of testStatuses) { + if (testResult.succeeded) { + numberOfSuccesses++; + } else { + numberOfFailures++; + } + } + + if (numberOfFailures == 1) { + message += 'was 1 failure'; + } else { + message += `have been ${numberOfFailures} failures`; + } - // message += ' and there '; + message += ' and there '; - // if (numberOfSuccesses == 1) { - // message += 'has been 1 success'; - // } else { - // message += `have been ${numberOfSuccesses} successes`; - // } + if (numberOfSuccesses == 1) { + message += 'has been 1 success'; + } else { + message += `have been ${numberOfSuccesses} successes`; + } - // message += '.'; + message += '. See the console for more details.'; this.testRunNotice.setMessage(message); } - - // let numberOfSuccesses = 0; - // let numberOfFailures = 0; - // for (const testResult of testStatuses) { - // if (testResult.succeeded) { - // numberOfSuccesses++; - // } else { - // numberOfFailures++; - // } - // } } } diff --git a/__integration__/obsidian-mode.test.ts b/__integration__/obsidian-mode.test.ts index 1ab42f3e..8e80d3a9 100644 --- a/__integration__/obsidian-mode.test.ts +++ b/__integration__/obsidian-mode.test.ts @@ -1,5 +1,5 @@ import TestLinterPlugin, {IntegrationTestCase} from './main.test'; -import {Editor} from 'obsidian'; +import {Editor, TFile} from 'obsidian'; import expect from 'expect'; import {setWorkspaceItemMode} from './utils.test'; import moment from 'moment'; @@ -24,8 +24,8 @@ function modeAssertions(editor: Editor) { expect(editor.posToOffset(editor.getCursor())).toBe(cursorStart+1); } -function edgeCaseExpectedTextModifications(text: string):string { - text = text.replace('{{created_date}}', moment().format('YYYY-MM-DD')); +function edgeCaseExpectedTextModifications(text: string, file: TFile):string { + text = text.replace('{{created_date}}', moment(file.stat.ctime ?? '').format('YYYY-MM-DD')); text = text.replace('{{modified_date}}', moment().format('YYYY-MM-DD')); return text; diff --git a/test-vault/obsidian-mode/edge-case-yaml.linted.md b/test-vault/obsidian-mode/edge-case-yaml.linted.md index cacc78a0..7570d965 100644 --- a/test-vault/obsidian-mode/edge-case-yaml.linted.md +++ b/test-vault/obsidian-mode/edge-case-yaml.linted.md @@ -14,7 +14,7 @@ readings: - "[[test]]" - "[[test 2#1.1 test chapter]]" -created: 2024-08-21 +created: {{created_date}} last_modified: {{modified_date}} --- From 2b790cb41f7853b05f5e44bcdca5e68dfb992717 Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Fri, 13 Sep 2024 19:00:28 -0400 Subject: [PATCH 8/9] fixed the issue with console logs being present --- src/main.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index ec27c15a..3a118824 100644 --- a/src/main.ts +++ b/src/main.ts @@ -620,12 +620,9 @@ export default class LinterPlugin extends Plugin { // so we will too. const text = plainClipboard.trim(); if (urlRegex.test(text)) { - // debugger; - console.log('failed: "' + text + '"'); logWarn(getTextInLanguage('logs.paste-link-warning')); return; } - console.log('passed: "' + text + '"'); // prevent default pasting & abort when not successful clipboardEv.stopPropagation(); From ef0c944032fc16efc082711e369687427f36604d Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Fri, 13 Sep 2024 19:07:19 -0400 Subject: [PATCH 9/9] remove unused helper function --- __integration__/utils.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/__integration__/utils.test.ts b/__integration__/utils.test.ts index 00a37438..19bc624e 100644 --- a/__integration__/utils.test.ts +++ b/__integration__/utils.test.ts @@ -1,7 +1,5 @@ import {App, FileView} from 'obsidian'; -export const sleep = (delay: number) => new Promise((resolve) => setTimeout(resolve, delay)); - export async function setWorkspaceItemMode(app: App, source: boolean) { const view: FileView = app.workspace.getActiveFileView(); if (!view) {