Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging to help deflaking tests #65

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
15 changes: 11 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 3 additions & 1 deletion src/codeactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
41 changes: 30 additions & 11 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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())!;
Expand All @@ -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())!;
Expand All @@ -147,15 +147,15 @@ 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())!;
const diagnosticsList = new Diagnostics().diagnose(document, messageList, errors, undefined);

assert.equal(diagnosticsList.every(item => item.code !== id), true);
});
});
}).timeout(10000);

const testFolderLocation: string = "/../../../src/test/";

Expand All @@ -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
Expand All @@ -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.CodeAction[]>("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.CodeAction[]>("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);
Expand Down
Loading