diff --git a/package.json b/package.json
index 3bbd8ce..3aa6ecd 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
"lint:staged": "nice-move lint staged",
"prepare": "git config core.hooksPath .githooks",
"prepublishOnly": "npm run lint:staged && npm test",
+ "snapshot": "ava --fail-fast -u -w",
"test": "ava --fail-fast"
},
"dependencies": {
diff --git a/test/snapshots/test.mjs.md b/test/snapshots/test.mjs.md
new file mode 100644
index 0000000..ef05d50
--- /dev/null
+++ b/test/snapshots/test.mjs.md
@@ -0,0 +1,120 @@
+# Snapshot report for `test/test.mjs`
+
+The actual snapshot is saved in `test.mjs.snap`.
+
+Generated by [AVA](https://avajs.dev).
+
+## preprocess
+
+> Snapshot 1
+
+ {
+ filename: 'fake.htm/0/html-script-module.js',
+ text: `␊
+ ␊
+ 'use strict';␊
+ `,
+ }
+
+> Snapshot 2
+
+ {
+ filename: 'fake.htm/1/html-script-legacy.js',
+ text: `␊
+ ␊
+ ␊
+ ␊
+ ␊
+ alert();␊
+ `,
+ }
+
+## module
+
+> Snapshot 1
+
+ {
+ errorCount: 0,
+ fatalErrorCount: 0,
+ filePath: 'D:\\open\\eslint-plugin-html\\fake.html',
+ fixableErrorCount: 0,
+ fixableWarningCount: 1,
+ messages: [
+ {
+ column: 7,
+ endColumn: 20,
+ endLine: 3,
+ fix: {
+ range: [
+ 34,
+ 47,
+ ],
+ text: '',
+ },
+ line: 3,
+ message: '\'use strict\' is unnecessary inside of modules.',
+ messageId: 'module',
+ nodeType: 'ExpressionStatement',
+ ruleId: 'strict',
+ severity: 1,
+ },
+ ],
+ source: `␊
+ ␊
+ `,
+ suppressedMessages: [],
+ usedDeprecatedRules: [],
+ warningCount: 1,
+ }
+
+## legacy
+
+> Snapshot 1
+
+ {
+ errorCount: 0,
+ fatalErrorCount: 0,
+ filePath: 'D:\\open\\eslint-plugin-html\\fake.htm',
+ fixableErrorCount: 0,
+ fixableWarningCount: 0,
+ messages: [
+ {
+ column: 7,
+ endColumn: 15,
+ endLine: 3,
+ line: 3,
+ message: 'Use the global form of \'use strict\'.',
+ messageId: 'global',
+ nodeType: 'Program',
+ ruleId: 'strict',
+ severity: 1,
+ },
+ ],
+ source: `␊
+ ␊
+ `,
+ suppressedMessages: [],
+ usedDeprecatedRules: [],
+ warningCount: 1,
+ }
+
+## fix
+
+> Snapshot 1
+
+ `␊
+ ␊
+ abc␊
+ `
+
+> Snapshot 2
+
+ []
diff --git a/test/snapshots/test.mjs.snap b/test/snapshots/test.mjs.snap
new file mode 100644
index 0000000..71cf0a2
Binary files /dev/null and b/test/snapshots/test.mjs.snap differ
diff --git a/test/test.mjs b/test/test.mjs
index 843c3b9..8f284d0 100644
--- a/test/test.mjs
+++ b/test/test.mjs
@@ -20,14 +20,8 @@ test('preprocess', (t) => {
const [first, second] = processor.preprocess(code, 'fake.htm');
- t.deepEqual(first, {
- filename: 'fake.htm/0/html-script-module.js',
- text: "\n \n 'use strict';\n ",
- });
- t.deepEqual(second, {
- filename: 'fake.htm/1/html-script-legacy.js',
- text: '\n \n \n \n \n alert();\n ',
- });
+ t.snapshot(first);
+ t.snapshot(second);
});
test('module', async (t) => {
@@ -41,14 +35,7 @@ test('module', async (t) => {
filePath: 'fake.html',
});
- t.true(
- result.messages.some(
- (message) =>
- message.ruleId === 'strict' &&
- message.column === 7 &&
- message.severity === 1,
- ),
- );
+ t.snapshot(result);
});
test('legacy', async (t) => {
@@ -62,14 +49,7 @@ test('legacy', async (t) => {
filePath: 'fake.htm',
});
- t.true(
- result.messages.some(
- (message) =>
- message.ruleId === 'strict' &&
- message.column === 7 &&
- message.severity === 1,
- ),
- );
+ t.snapshot(result);
});
test('fix', (t) => {
@@ -81,15 +61,6 @@ test('fix', (t) => {
abc
`;
- const expected = html`
-
- abc
- `;
-
const messages = linter.verifyAndFix(
code,
{
@@ -108,6 +79,6 @@ test('fix', (t) => {
);
t.true(messages.fixed);
- t.is(messages.output, expected);
- t.deepEqual(messages.messages, []);
+ t.snapshot(messages.output);
+ t.snapshot(messages.messages);
});