Skip to content

Commit

Permalink
Add logging to help deflagging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Sep 26, 2024
1 parent 6505618 commit f82ffdb
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 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,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())!;
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f82ffdb

Please sign in to comment.