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' 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 7eeccc3..88b6712 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())!; @@ -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/"; @@ -165,11 +165,16 @@ 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) { + 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); // Parse original @@ -178,13 +183,27 @@ 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( editor.document.positionAt(item.start + 1), editor.document.positionAt(item.end - 1) )); - await vscode.workspace.applyEdit(actions[0].edit as vscode.WorkspaceEdit); + + + 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); // Compare with golden await compareGolden(editor.document.getText(), goldenFile);