Adds a valid case (PortalLayoutV2 under pages-v2/portal) and an invalid case (OrganizerLayoutV2 under pages-v2/portal -> wrongLayout) so the rule's portal-path branch has positive + negative coverage. Closes the Task 5 code-review Important finding. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { createRequire } from 'node:module'
|
|
import { RuleTester } from 'eslint'
|
|
|
|
// Project is ESLint 8.57 — RuleTester uses the legacy `parser` +
|
|
// `parserOptions` shape (NOT ESLint-9 `languageOptions`). createRequire
|
|
// gives us a CJS `require` inside this ESM test for the .cjs rule + the
|
|
// parser path.
|
|
//
|
|
// RuleTester.run internally calls describe/it itself — do NOT wrap it in
|
|
// an `it()` block; call it directly inside (or at the top level of) the
|
|
// describe so Vitest does not see a describe-inside-it violation.
|
|
const require = createRequire(import.meta.url)
|
|
const rule = require('../require-v2-layout-meta.cjs')
|
|
|
|
const ruleTester = new RuleTester({
|
|
parser: require.resolve('vue-eslint-parser'),
|
|
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
|
})
|
|
|
|
ruleTester.run('require-v2-layout-meta', rule, {
|
|
valid: [
|
|
{
|
|
filename: 'src/pages-v2/dashboard.vue',
|
|
code: '<script setup lang="ts">definePage({ meta: { layout: \'OrganizerLayoutV2\' } })</script><template><div/></template>',
|
|
},
|
|
{
|
|
filename: 'src/pages/dashboard.vue',
|
|
code: '<script setup lang="ts">const x = 1</script><template><div/></template>',
|
|
},
|
|
{
|
|
// pages-v2/portal/** expects PortalLayoutV2, not OrganizerLayoutV2
|
|
filename: 'src/pages-v2/portal/artists.vue',
|
|
code: '<script setup lang="ts">definePage({ meta: { layout: \'PortalLayoutV2\' } })</script><template><div/></template>',
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
// OrganizerLayoutV2 is wrong under the portal subtree
|
|
filename: 'src/pages-v2/portal/artists.vue',
|
|
code: '<script setup lang="ts">definePage({ meta: { layout: \'OrganizerLayoutV2\' } })</script><template><div/></template>',
|
|
errors: [{ messageId: 'wrongLayout' }],
|
|
},
|
|
{
|
|
filename: 'src/pages-v2/dashboard.vue',
|
|
code: '<script setup lang="ts">const x = 1</script><template><div/></template>',
|
|
errors: [{ messageId: 'missing' }],
|
|
},
|
|
{
|
|
filename: 'src/pages-v2/events/index.vue',
|
|
code: '<script setup lang="ts">definePage({ meta: { layout: \'default\' } })</script><template><div/></template>',
|
|
errors: [{ messageId: 'wrongLayout' }],
|
|
},
|
|
],
|
|
})
|