Skip to content

Commit

Permalink
chore(outdated docs): improve documentation (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
veritem authored Dec 10, 2023
1 parent ffce7e1 commit bbedf7c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 81 deletions.
103 changes: 52 additions & 51 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Require local Test Context for concurrent snapshot tests (`vitest/require-local-test-context-for-concurrent-snapshots`)

💼 This rule is enabled in the ✅ `recommended` config.
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const recommended = {
[validTitleName]: 'error',
[validExpectName]: 'error',
[validDescribeCallbackName]: 'error',
[requireLocalTestContextForConcurrentSnapshotsName]: 'error',
[requireLocalTestContextForConcurrentSnapshotsName]: 'error'
}

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-done-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default createEslintRule<Options, MessageIds>({
if (isVitestEach && node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression)
return

const isVitestConcurrent = getNodeName(node.callee)?.endsWith('.concurrent') ?? false;
const isVitestConcurrent = getNodeName(node.callee)?.endsWith('.concurrent') ?? false
if (isVitestConcurrent) return

const callback = findCallbackArg(node, isVitestEach, context)
Expand Down
46 changes: 23 additions & 23 deletions src/rules/require-local-test-context-for-concurrent-snapshots.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils";
import { createEslintRule, getNodeName, isSupportedAccessor } from "../utils";
import { isTypeOfVitestFnCall } from "../utils/parseVitestFnCall";
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import { createEslintRule, isSupportedAccessor } from '../utils'
import { isTypeOfVitestFnCall } from '../utils/parseVitestFnCall'

export const RULE_NAME = "require-local-test-context-for-concurrent-snapshots";
export const RULE_NAME = 'require-local-test-context-for-concurrent-snapshots'

export default createEslintRule({
name: RULE_NAME,
meta: {
docs: {
description: "Require local Test Context for concurrent snapshot tests",
recommended: "error",
description: 'Require local Test Context for concurrent snapshot tests',
recommended: 'error'
},
messages: {
requireLocalTestContext: "Use local Test Context instead",
requireLocalTestContext: 'Use local Test Context instead'
},
type: "problem",
schema: [],
type: 'problem',
schema: []
},
defaultOptions: [],
create(context) {
return {
CallExpression(node) {
const isNotAnAssertion = !isTypeOfVitestFnCall(node, context, ['expect'])
if (isNotAnAssertion) return;
if (isNotAnAssertion) return

const isNotASnapshotAssertion = ![
'toMatchSnapshot',
'toMatchInlineSnapshot'
].includes(node.callee.property.name);
].includes(node.callee.property.name)

if (isNotASnapshotAssertion) return;
if (isNotASnapshotAssertion) return

const isInsideSequentialDescribeOrTest = !context.getAncestors().some((ancestor) => {
if (ancestor.type !== AST_NODE_TYPES.CallExpression) return false;
if (ancestor.type !== AST_NODE_TYPES.CallExpression) return false

const isNotInsideDescribeOrTest = !isTypeOfVitestFnCall(ancestor, context, ["describe", "test"]);
if (isNotInsideDescribeOrTest) return false;
const isNotInsideDescribeOrTest = !isTypeOfVitestFnCall(ancestor, context, ['describe', 'test'])
if (isNotInsideDescribeOrTest) return false

const isTestRunningConcurrently =
ancestor.callee.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(ancestor.callee.property, "concurrent");
isSupportedAccessor(ancestor.callee.property, 'concurrent')

return isTestRunningConcurrently
});
})

if (isInsideSequentialDescribeOrTest) return;
if (isInsideSequentialDescribeOrTest) return

context.report({
node,
messageId: "requireLocalTestContext"
messageId: 'requireLocalTestContext'
})
},
};
},
});
}
}
}
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import rule, { RULE_NAME } from '../src/rules/require-local-test-context-for-concurrent-snapshots'
import { ruleTester } from "./ruleTester";
import { ruleTester } from './ruleTester'

ruleTester.run(RULE_NAME, rule, {
valid: [
Expand All @@ -15,7 +15,7 @@ ruleTester.run(RULE_NAME, rule, {
'describe("something", () => { it("something", (context) => { expect(1).toMatchInlineSnapshot() }) })',
'describe("something", () => { it("something", (context) => { context.expect(1).toMatchInlineSnapshot() }) })',
'describe("something", () => { it("something", (context) => { expect(1).toMatchInlineSnapshot() }) })',
'it.concurrent("something", (context) => { context.expect(1).toMatchSnapshot() })',
'it.concurrent("something", (context) => { context.expect(1).toMatchSnapshot() })'
],
invalid: [
{
Expand Down Expand Up @@ -53,6 +53,6 @@ ruleTester.run(RULE_NAME, rule, {
expect(true).toMatchSnapshot();
})`,
errors: [{ messageId: 'requireLocalTestContext' }]
},
],
}
]
})

0 comments on commit bbedf7c

Please sign in to comment.