Skip to content

Commit 10ac0c1

Browse files
committed
test: switch to snapshot tests
1 parent 98e95c4 commit 10ac0c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+63
-71
lines changed

README.md

+4-4

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.3",
44
"description": "A Vale-compatible prose style for non-native English speaker",
55
"scripts": {
6+
"snapshot:update": "vitest rules --update",
67
"test": "vitest rules",
78
"dist": "zip -r Prim.zip Prim -x \"*.DS_Store\""
89
},

test/expectations/Semicolon.log

-1
This file was deleted.

test/expectations/WordRepitition.log

-1
This file was deleted.

fixtures/AMPM/.vale.ini renamed to test/fixtures/AMPM/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/AbbreviationPeriods/.vale.ini renamed to test/fixtures/AbbreviationPeriods/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Ambiguity/.vale.ini renamed to test/fixtures/Ambiguity/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Contractions/.vale.ini renamed to test/fixtures/Contractions/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Ellipsis/.vale.ini renamed to test/fixtures/Ellipsis/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/EmDash/.vale.ini renamed to test/fixtures/EmDash/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/EnDash/.vale.ini renamed to test/fixtures/EnDash/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Latin/.vale.ini renamed to test/fixtures/Latin/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/OptionalPlurals/.vale.ini renamed to test/fixtures/OptionalPlurals/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Ordinal/.vale.ini renamed to test/fixtures/Ordinal/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/OxfordComma/.vale.ini renamed to test/fixtures/OxfordComma/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Percentages/.vale.ini renamed to test/fixtures/Percentages/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/PreferredAlternatives/.vale.ini renamed to test/fixtures/PreferredAlternatives/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/RequiredAlternatives/.vale.ini renamed to test/fixtures/RequiredAlternatives/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Semicolon/.vale.ini renamed to test/fixtures/Semicolon/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/SentenceLength/.vale.ini renamed to test/fixtures/SentenceLength/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/SimplerAlternatives/.vale.ini renamed to test/fixtures/SimplerAlternatives/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/Space/.vale.ini renamed to test/fixtures/Space/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

fixtures/WordRepitition/.vale.ini renamed to test/fixtures/WordRepitition/.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StylesPath = ../../
1+
StylesPath = ../../../
22

33
MinAlertLevel = suggestion
44

test/rules.parameters.js

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
import fs from "fs";
22
import path from "path";
33

4-
function* walkSync(dir) {
5-
const files = fs.readdirSync(dir, { withFileTypes: true });
6-
for (const file of files) {
7-
if (file.isDirectory()) {
8-
yield* walkSync(path.join(dir, file.name));
9-
} else {
10-
yield path.join(dir, file.name);
11-
}
12-
}
13-
}
4+
const testDirectory = "test";
5+
const fixturesDirectory = "fixtures";
146

15-
const dir = path.resolve(process.cwd(), "test", "expectations");
16-
const extension = ".log";
17-
const parameters = [];
7+
const fixturesRoot = path.resolve(process.cwd(), testDirectory, fixturesDirectory);
8+
const parameters = fs.readdirSync(fixturesRoot, {
9+
withFileTypes: false,
10+
recursive: false
11+
}).map(fpath => path.basename(fpath));
1812

19-
for (const filePath of walkSync(dir)) {
20-
if (path.extname(filePath).toLowerCase() === extension) {
21-
const fileName = path.basename(filePath).replace(extension, "");
22-
const fileContent = fs.readFileSync(filePath).toString().trim();
23-
parameters.push([fileName, fileContent]);
24-
}
25-
}
26-
27-
export default parameters;
13+
export {
14+
parameters as default,
15+
testDirectory,
16+
fixturesDirectory
17+
};

test/rules.test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path";
22
import { execa } from "execa";
3-
import { expect, test } from "vitest";
4-
import scenario from "./rules.parameters.js";
3+
import { expect, it } from "vitest";
4+
import scenario, { testDirectory, fixturesDirectory } from "./rules.parameters.js";
55

66
const command = "vale";
77
const args = [
@@ -11,17 +11,18 @@ const args = [
1111
"--relative",
1212
"test.md"
1313
]
14-
const fixturesDirectory = "fixtures";
14+
const snapshotsDirectory = "snapshots";
1515

16-
test.each(scenario)(`Test: %s`, async (rule, expected) => {
16+
it.each(scenario)(`Test: %s`, async (rule) => {
1717
let result;
1818
try {
19-
const cwd = path.resolve(process.cwd(), fixturesDirectory, rule);
20-
const output = await execa(command, args, { cwd: cwd });
19+
const fixtureLocation = path.resolve(process.cwd(), testDirectory, fixturesDirectory, rule);
20+
const output = await execa(command, args, { cwd: fixtureLocation });
2121
result = output.stdout;
2222
} catch (error) {
2323
result = error.stdout;
2424
}
2525

26-
expect.soft(result.trim()).toBe(expected);
26+
const snapshotFile = path.resolve(process.cwd(), testDirectory, snapshotsDirectory, `${rule}.log`);
27+
await expect(result).toMatchFileSnapshot(snapshotFile);
2728
});

test/expectations/AMPM.log renamed to test/snapshots/AMPM.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ test.md:3:24:Prim.AMPM:Use 'am' or 'pm' else 'a.m.' or 'p.m.' (preceded by a spa
22
test.md:4:33:Prim.AMPM:Use 'am' or 'pm' else 'a.m.' or 'p.m.' (preceded by a space).
33
test.md:4:41:Prim.AMPM:Use 'am' or 'pm' else 'a.m.' or 'p.m.' (preceded by a space).
44
test.md:5:33:Prim.AMPM:Use 'am' or 'pm' else 'a.m.' or 'p.m.' (preceded by a space).
5-
test.md:6:30:Prim.AMPM:Use 'am' or 'pm' else 'a.m.' or 'p.m.' (preceded by a space).
5+
test.md:6:30:Prim.AMPM:Use 'am' or 'pm' else 'a.m.' or 'p.m.' (preceded by a space).
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test.md:3:45:Prim.AbbreviationPeriods:Don't use periods with abbreviations such as 'H.T.T.P.S.'.
1+
test.md:3:45:Prim.AbbreviationPeriods:Don't use periods with abbreviations such as 'H.T.T.P.S.'.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test.md:3:49:Prim.Ambiguity:Avoid ambiguity. Don't use 'and/or'.
1+
test.md:3:49:Prim.Ambiguity:Avoid ambiguity. Don't use 'and/or'.

test/expectations/Contractions.log renamed to test/snapshots/Contractions.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ test.md:267:14:Prim.Contractions:Avoid contractions. Use 'you are' instead of 'y
103103
test.md:270:1:Prim.Contractions:Avoid contractions. Use 'You had' or 'You would' instead of 'You'd'.
104104
test.md:271:4:Prim.Contractions:Avoid contractions. Use 'you had' or 'you would' instead of 'you'd'.
105105
test.md:274:7:Prim.Contractions:Avoid contractions. Use 'you have' instead of 'you've'.
106-
test.md:277:1:Prim.Contractions:Avoid contractions. Use 'You will' instead of 'You'll'.
106+
test.md:277:1:Prim.Contractions:Avoid contractions. Use 'You will' instead of 'You'll'.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test.md:3:23:Prim.Ellipsis:In general, don't use an ellipsis.
2-
test.md:4:22:Prim.Ellipsis:In general, don't use an ellipsis.
2+
test.md:4:22:Prim.Ellipsis:In general, don't use an ellipsis.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test.md:3:16:Prim.EmDash:Add spaces around '—'.
2-
test.md:3:45:Prim.EmDash:Add spaces around '—'.
2+
test.md:3:45:Prim.EmDash:Add spaces around '—'.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
test.md:3:47:Prim.EnDash:Remove the spaces around '–'.
22
test.md:4:31:Prim.EnDash:Remove the spaces around '–'.
3-
test.md:5:42:Prim.EnDash:Remove the spaces around '–'.
3+
test.md:5:42:Prim.EnDash:Remove the spaces around '–'.

test/expectations/Latin.log renamed to test/snapshots/Latin.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ test.md:21:33:Prim.Latin:Avoid latin. Use 'that is' instead of 'ie,'.
99
test.md:24:22:Prim.Latin:Avoid latin. Use 'against' instead of 'vs.'.
1010
test.md:27:26:Prim.Latin:Avoid latin. Use 'against' instead of 'versus'.
1111
test.md:30:33:Prim.Latin:Avoid latin. Use 'over' or 'through' instead of 'via'.
12-
test.md:33:31:Prim.Latin:Avoid latin. Use 'namely' instead of 'viz.'.
12+
test.md:33:31:Prim.Latin:Avoid latin. Use 'namely' instead of 'viz.'.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test.md:3:23:Prim.OptionalPlurals:Don't use plurals in parentheses such as in 'extension(s)'.
2-
test.md:4:5:Prim.OptionalPlurals:Don't use plurals in parentheses such as in 'checkbox(es)'.
2+
test.md:4:5:Prim.OptionalPlurals:Don't use plurals in parentheses such as in 'checkbox(es)'.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
test.md:3:1:Prim.Ordinal:Don't add -ly to an ordinal number.
22
test.md:3:45:Prim.Ordinal:Don't add -ly to an ordinal number.
3-
test.md:3:84:Prim.Ordinal:Don't add -ly to an ordinal number.
3+
test.md:3:84:Prim.Ordinal:Don't add -ly to an ordinal number.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test.md:3:41:Prim.OxfordComma:Use the Oxford comma in 'flour, sugar, eggs and butter.'.
2-
test.md:5:20:Prim.OxfordComma:Use the Oxford comma in 'clothes, toiletries or books?'.
2+
test.md:5:20:Prim.OxfordComma:Use the Oxford comma in 'clothes, toiletries or books?'.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test.md:3:28:Prim.Percentages:Use a numeral to represent a percentage.
1+
test.md:3:28:Prim.Percentages:Use a numeral to represent a percentage.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
test.md:4:36:Prim.PreferredAlternatives:Prefer using 'Zero-day' over '0-day'.
22
test.md:7:39:Prim.PreferredAlternatives:Prefer using 'Midnight' over '12 am'.
3-
test.md:10:30:Prim.PreferredAlternatives:Prefer using 'Noon' over '12 pm'.
3+
test.md:10:30:Prim.PreferredAlternatives:Prefer using 'Noon' over '12 pm'.

test/expectations/RequiredAlternatives.log renamed to test/snapshots/RequiredAlternatives.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ test.md:7:27:Prim.RequiredAlternatives:Use '3D' instead of '3-D'.
33
test.md:10:19:Prim.RequiredAlternatives:Use 'sync' instead of 'synch'.
44
test.md:13:17:Prim.RequiredAlternatives:Use 'URL' instead of 'url'.
55
test.md:14:5:Prim.RequiredAlternatives:Use 'URL of' instead of 'URL for'.
6-
test.md:15:10:Prim.RequiredAlternatives:Use 'a URL' instead of 'an URL'.
6+
test.md:15:10:Prim.RequiredAlternatives:Use 'a URL' instead of 'an URL'.

test/snapshots/Semicolon.log

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.md:3:33:Prim.Semicolon:Try to simplify this sentence.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test.md:3:1:Prim.SentenceLength:Try to keep sentences short (< 30 words).
1+
test.md:3:1:Prim.SentenceLength:Try to keep sentences short (< 30 words).
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test.md:4:31:Prim.SimplerAlternatives:Use 'about' instead of 'approximately'.
1+
test.md:4:31:Prim.SimplerAlternatives:Use 'about' instead of 'approximately'.

test/expectations/Space.log renamed to test/snapshots/Space.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ test.md:4:35:Prim.Space:'door. It' should have one space between them.
33
test.md:5:18:Prim.Space:'melody.It' should have one space between them.
44
test.md:6:29:Prim.Space:'ruins? They' should have one space between them.
55
test.md:7:32:Prim.Space:', marveling' should have one space between them.
6-
test.md:8:1:Prim.Space:'Whoa! This' should have one space between them.
6+
test.md:8:1:Prim.Space:'Whoa! This' should have one space between them.

test/snapshots/WordRepitition.log

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.md:3:14:Prim.WordRepitition:'zoom' is repeated.

0 commit comments

Comments
 (0)