From f82ffdb7cd92aeaac3e4659a2828b6de103375b3 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 15:02:12 +0200 Subject: [PATCH 01/14] Add logging to help deflagging tests --- src/test/suite/extension.test.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 7eeccc3..2bf2d11 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -86,17 +86,17 @@ suite('Extension Test Suite', async () => { test("Test quickfix for missing Metadata", async () => { await updateConfiguration(null); - await testFixAgainstGolden('quickfix.arb', getFirstKey, 'quickfix.golden'); + await testFixAgainstGolden('quickfix.arb', getFirstKey, 'quickfix.golden', "Add metadata for key 'helloAndWelcome2'"); }); test("Test quickfix for placeholder without metadata with tabs", async () => { await updateConfiguration(null); - await testFixAgainstGolden('quickfix2.arb', getPlaceholder, 'quickfix2.golden'); + await testFixAgainstGolden('quickfix2.arb', getPlaceholder, 'quickfix2.golden', "Add metadata for placeholder 'firstName'"); }); test("Test quickfix for placeholder without metadata with spaces", async () => { await updateConfiguration(null); - await testFixAgainstGolden('quickfix2_spaces.arb', getPlaceholder, 'quickfix2_spaces.golden'); + await testFixAgainstGolden('quickfix2_spaces.arb', getPlaceholder, 'quickfix2_spaces.golden', "Add metadata for placeholder 'firstName'"); }); test("Test finding unescaped regions", async () => { @@ -123,7 +123,7 @@ suite('Extension Test Suite', async () => { test("Test suppressed warning with id missing_metadata_for_key", async () => { const id = DiagnosticCode.missingMetadataForKey; await updateConfiguration([id]); - + const document = await getEditor('quickfix.arb'); const [, messageList, errors] = new Parser().parse(document.document.getText())!; @@ -135,7 +135,7 @@ suite('Extension Test Suite', async () => { test("Test suppressed warning with id 'invalid_key', 'missing_metadata_for_key'", async () => { const ids = [DiagnosticCode.invalidKey, DiagnosticCode.missingMetadataForKey]; await updateConfiguration(ids); - + const document = await getEditor('testarb_2.arb'); const [, messageList, errors] = new Parser().parse(document.document.getText())!; @@ -147,7 +147,7 @@ suite('Extension Test Suite', async () => { test("Test suppressed warning with code 'metadata_for_missing_key'", async () => { const id = DiagnosticCode.metadataForMissingKey; await updateConfiguration([id]); - + const document = await getEditor('testarb_2.arb'); const [, messageList, errors] = new Parser().parse(document.document.getText())!; @@ -165,15 +165,14 @@ function getFirstKey(messageList: MessageList) { function getPlaceholder(messageList: MessageList) { const message = messageList.messageEntries[0].message as CombinedMessage; - const entry = message.getPlaceholders()[0]; - return entry; + return message.getPlaceholders()[0]; } -async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messageList: MessageList) => Literal, goldenFile: string) { +async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messageList: MessageList) => Literal, goldenFile: string, name: string) { const editor = await getEditor(testFile); // Parse original - const [, messageList,] = new Parser().parse(editor.document.getText()); + const [, messageList] = new Parser().parse(editor.document.getText()); // Apply fix for placeholder not defined in metadata const item = getItemFromParsed(messageList); @@ -184,7 +183,11 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag editor.document.positionAt(item.start + 1), editor.document.positionAt(item.end - 1) )); - await vscode.workspace.applyEdit(actions[0].edit as vscode.WorkspaceEdit); + + assert.equal(name, actions[0].title, `Available actions: ${actions.map(action => action.title).join('\n')}`); + const edit = actions[0].edit as vscode.WorkspaceEdit; + + await vscode.workspace.applyEdit(edit); // Compare with golden await compareGolden(editor.document.getText(), goldenFile); From b425ffea0b5e48ccb8773c1c50a76c69e8dc4aa6 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 15:12:37 +0200 Subject: [PATCH 02/14] Run multiple times --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5509890..6f33628 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,12 +14,16 @@ jobs: steps: - name: Checkout uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 + - name: Install Node.js uses: actions/setup-node@eff380dfbcf941bf8832e4acb788cebe13dfd758 with: node-version: 18.16.0 + - run: npm install - - run: xvfb-run -a npm test + + - run: for i in {1..10}; do xvfb-run -a npm test; done if: runner.os == 'Linux' - - run: npm test + + - run: 1..10 | % { npm test } if: runner.os != 'Linux' From 6da06281677160b71985568da4cd61c4b23761b6 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 15:17:54 +0200 Subject: [PATCH 03/14] fix mac --- .github/workflows/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6f33628..90b8051 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,10 @@ jobs: - run: npm install - run: for i in {1..10}; do xvfb-run -a npm test; done - if: runner.os == 'Linux' + if: matrix.os == 'ubuntu-latest' - run: 1..10 | % { npm test } - if: runner.os != 'Linux' + if: matrix.os == 'windows-latest' + + - run: for i in {1..10}; do npm test; done + if: matrix.os == 'macos-latest' From e2bc5d536687f9e61cb6240836f2c787cc89e835 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 15:22:59 +0200 Subject: [PATCH 04/14] Run 100 times! --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90b8051..dd32cb5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,11 +22,11 @@ jobs: - run: npm install - - run: for i in {1..10}; do xvfb-run -a npm test; done + - run: for i in {1..100}; do xvfb-run -a npm test; done if: matrix.os == 'ubuntu-latest' - - run: 1..10 | % { npm test } + - run: 1..100 | % { npm test } if: matrix.os == 'windows-latest' - - run: for i in {1..10}; do npm test; done + - run: for i in {1..100}; do npm test; done if: matrix.os == 'macos-latest' From ea858d6622cdc3e45fee03e3064616518c1a3b3b Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 15:35:20 +0200 Subject: [PATCH 05/14] Add delay --- src/test/suite/extension.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 2bf2d11..29c07eb 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -177,6 +177,8 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag // Apply fix for placeholder not defined in metadata const item = getItemFromParsed(messageList); + await new Promise(f => setTimeout(f, 250)); + const actions = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", editor.document.uri, new vscode.Range( From 60b03652377b6b5aabc7c0112105d3f664030dfd Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 15:40:47 +0200 Subject: [PATCH 06/14] Longer delay --- src/test/suite/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 29c07eb..039d70b 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -177,7 +177,7 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag // Apply fix for placeholder not defined in metadata const item = getItemFromParsed(messageList); - await new Promise(f => setTimeout(f, 250)); + await new Promise(f => setTimeout(f, 500)); const actions = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", editor.document.uri, From a3b76abd41ad65cddc6a48e5cf32697ecce5b3da Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:05:55 +0200 Subject: [PATCH 07/14] Assert that the extension is active --- src/test/suite/extension.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 039d70b..7a20964 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -169,6 +169,10 @@ function getPlaceholder(messageList: MessageList) { } async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messageList: MessageList) => Literal, goldenFile: string, name: string) { + const ext = vscode.extensions.getExtension("Google.arb-editor"); + await ext?.activate(); + assert.ok(ext?.isActive); + const editor = await getEditor(testFile); // Parse original From 62046bd810f4edda17cf407477bacf369c0e0bd6 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:08:04 +0200 Subject: [PATCH 08/14] Back to 10 reps --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd32cb5..90b8051 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,11 +22,11 @@ jobs: - run: npm install - - run: for i in {1..100}; do xvfb-run -a npm test; done + - run: for i in {1..10}; do xvfb-run -a npm test; done if: matrix.os == 'ubuntu-latest' - - run: 1..100 | % { npm test } + - run: 1..10 | % { npm test } if: matrix.os == 'windows-latest' - - run: for i in {1..100}; do npm test; done + - run: for i in {1..10}; do npm test; done if: matrix.os == 'macos-latest' From 6f26ff9f5188cc47529839f4b27a46f037a48a96 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:12:08 +0200 Subject: [PATCH 09/14] Reset test file --- .github/workflows/main.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90b8051..5509890 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,19 +14,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 - - name: Install Node.js uses: actions/setup-node@eff380dfbcf941bf8832e4acb788cebe13dfd758 with: node-version: 18.16.0 - - run: npm install - - - run: for i in {1..10}; do xvfb-run -a npm test; done - if: matrix.os == 'ubuntu-latest' - - - run: 1..10 | % { npm test } - if: matrix.os == 'windows-latest' - - - run: for i in {1..10}; do npm test; done - if: matrix.os == 'macos-latest' + - run: xvfb-run -a npm test + if: runner.os == 'Linux' + - run: npm test + if: runner.os != 'Linux' From 9e297d959d1d01d64be7d3010b12de4151222cac Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:17:11 +0200 Subject: [PATCH 10/14] Add debug logging --- src/test/suite/extension.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 7a20964..615e7fa 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -169,9 +169,11 @@ function getPlaceholder(messageList: MessageList) { } async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messageList: MessageList) => Literal, goldenFile: string, name: string) { + console.log(`1st try: ${vscode.extensions.getExtension("Google.arb-editor")?.isActive}`); const ext = vscode.extensions.getExtension("Google.arb-editor"); await ext?.activate(); assert.ok(ext?.isActive); + console.log(`2nd try: ${vscode.extensions.getExtension("Google.arb-editor")?.isActive}`); const editor = await getEditor(testFile); From c51176ed46167ebde4147b7387d7695cadf09800 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:17:46 +0200 Subject: [PATCH 11/14] Fix comma --- src/test/suite/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 615e7fa..fdd79cc 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -178,7 +178,7 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag const editor = await getEditor(testFile); // Parse original - const [, messageList] = new Parser().parse(editor.document.getText()); + const [, messageList,] = new Parser().parse(editor.document.getText()); // Apply fix for placeholder not defined in metadata const item = getItemFromParsed(messageList); From cfed27c49025afe0c11eca680b5c205fd4b7cfc4 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:23:13 +0200 Subject: [PATCH 12/14] Remove timeout --- src/test/suite/extension.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index fdd79cc..92d2cd7 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -183,8 +183,6 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag // Apply fix for placeholder not defined in metadata const item = getItemFromParsed(messageList); - await new Promise(f => setTimeout(f, 500)); - const actions = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", editor.document.uri, new vscode.Range( From 4e27d0724dd8722913d55366284c8a9a60c96f49 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Sep 2024 16:23:32 +0200 Subject: [PATCH 13/14] Add repeat --- .github/workflows/main.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5509890..dd32cb5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,12 +14,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 + - name: Install Node.js uses: actions/setup-node@eff380dfbcf941bf8832e4acb788cebe13dfd758 with: node-version: 18.16.0 + - run: npm install - - run: xvfb-run -a npm test - if: runner.os == 'Linux' - - run: npm test - if: runner.os != 'Linux' + + - run: for i in {1..100}; do xvfb-run -a npm test; done + if: matrix.os == 'ubuntu-latest' + + - run: 1..100 | % { npm test } + if: matrix.os == 'windows-latest' + + - run: for i in {1..100}; do npm test; done + if: matrix.os == 'macos-latest' From 924c309dbbd1ba4f59c178324bcc5448f8259dfb Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 27 Sep 2024 15:47:50 +0200 Subject: [PATCH 14/14] More debugging --- src/codeactions.ts | 4 +++- src/test/suite/extension.test.ts | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/codeactions.ts b/src/codeactions.ts index dc55081..ed59638 100644 --- a/src/codeactions.ts +++ b/src/codeactions.ts @@ -26,6 +26,7 @@ export class CodeActions implements vscode.CodeActionProvider { ]; provideCodeActions(document: vscode.TextDocument, range: vscode.Range | vscode.Selection, context: vscode.CodeActionContext, token: vscode.CancellationToken): vscode.CodeAction[] { + console.log(`Providing code actions for ${range.start} - ${range.end}`); const diagnostics = context.diagnostics; const newMetadataActions = diagnostics @@ -35,7 +36,8 @@ export class CodeActions implements vscode.CodeActionProvider { const undefinedPlaceholderActions = diagnostics .filter(diagnostic => diagnostic.code === DiagnosticCode.placeholderWithoutMetadata) .map(_ => this.createPlaceholder(document, range)); - + console.log(`newMetadataActions ${newMetadataActions}`); + console.log(`undefinedPlaceholderActions ${undefinedPlaceholderActions}`); return [...newMetadataActions, ...undefinedPlaceholderActions] .filter(codeAction => codeAction instanceof vscode.CodeAction) .map(codeAction => codeAction as vscode.CodeAction); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 92d2cd7..88b6712 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -155,7 +155,7 @@ suite('Extension Test Suite', async () => { assert.equal(diagnosticsList.every(item => item.code !== id), true); }); -}); +}).timeout(10000); const testFolderLocation: string = "/../../../src/test/"; @@ -170,9 +170,9 @@ function getPlaceholder(messageList: MessageList) { async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messageList: MessageList) => Literal, goldenFile: string, name: string) { console.log(`1st try: ${vscode.extensions.getExtension("Google.arb-editor")?.isActive}`); - const ext = vscode.extensions.getExtension("Google.arb-editor"); - await ext?.activate(); - assert.ok(ext?.isActive); + // const ext = vscode.extensions.getExtension("Google.arb-editor"); + // await ext?.activate(); + // assert.ok(ext?.isActive); console.log(`2nd try: ${vscode.extensions.getExtension("Google.arb-editor")?.isActive}`); const editor = await getEditor(testFile); @@ -183,6 +183,8 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag // Apply fix for placeholder not defined in metadata const item = getItemFromParsed(messageList); + console.log(`Item: ${item}`); + const actions = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", editor.document.uri, new vscode.Range( @@ -190,7 +192,15 @@ async function testFixAgainstGolden(testFile: string, getItemFromParsed: (messag editor.document.positionAt(item.end - 1) )); - assert.equal(name, actions[0].title, `Available actions: ${actions.map(action => action.title).join('\n')}`); + + const actions2 = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", + editor.document.uri, + new vscode.Range( + editor.document.positionAt(item.start + 1), + editor.document.positionAt(item.end - 1) + )); + + assert.equal(name, actions[0].title, `${actions.length} available actions: ${actions.map(action => action.title).join('\n')}, ${actions2.length} available actions: ${actions2.map(action => action.title).join('\n')}`); const edit = actions[0].edit as vscode.WorkspaceEdit; await vscode.workspace.applyEdit(edit);