Skip to content

Commit

Permalink
Fix the low-hanging test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Jun 16, 2024
1 parent 2a508e1 commit eb16c41
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions packages/steiger-plugin-fsd/src/_lib/find-all-recursively.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { basename } from 'node:path'
import type { Folder, File } from '@feature-sliced/filesystem'

import { parseIntoFsdRoot as parseIntoFolder } from './prepare-test.js'
import { joinFromRoot, parseIntoFsdRoot as parseIntoFolder } from './prepare-test.js'

/** Recursively walk through a folder and return all entries that satisfy the predicate in a flat array. */
export function findAllRecursively(folder: Folder, predicate: (entry: Folder | File) => boolean): Array<Folder | File> {
Expand Down Expand Up @@ -54,9 +54,9 @@ if (import.meta.vitest) {
)

expect(result.map((entry) => entry.path)).toEqual([
'/folder1/directory1',
'/folder2/folder3/directory2',
'/directory3',
joinFromRoot('folder1', 'directory1'),
joinFromRoot('folder2', 'folder3', 'directory2'),
joinFromRoot('directory3'),
])
})
}
6 changes: 3 additions & 3 deletions packages/steiger-plugin-fsd/src/_lib/group-slices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sep } from 'node:path'
import { sep, join } from 'node:path'

export function groupSlices(sliceNames: Array<string>): Record<string, Array<string>> {
const groups: Record<string, Array<string>> = {}
Expand All @@ -20,8 +20,8 @@ export function groupSlices(sliceNames: Array<string>): Record<string, Array<str
if (import.meta.vitest) {
const { test, expect } = import.meta.vitest
test('groupSlices', () => {
expect(groupSlices(['a/b/c', 'a/b/d', 'a/e', 'f', 'g'])).toEqual({
'a/b': ['c', 'd'],
expect(groupSlices([join('a', 'b', 'c'), join('a', 'b', 'd'), join('a', 'e'), 'f', 'g'])).toEqual({
[join('a', 'b')]: ['c', 'd'],
a: ['e'],
'': ['f', 'g'],
})
Expand Down
24 changes: 12 additions & 12 deletions packages/steiger-plugin-fsd/src/_lib/prepare-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,59 +85,59 @@ if (import.meta.vitest) {

expect(root).toEqual({
type: 'folder',
path: '/',
path: joinFromRoot(),
children: [
{
type: 'folder',
path: '/entities',
path: joinFromRoot('entities'),
children: [
{
type: 'folder',
path: '/entities/users',
path: joinFromRoot('entities', 'users'),
children: [
{
type: 'folder',
path: '/entities/users/ui',
path: joinFromRoot('entities', 'users', 'ui'),
children: [],
},
{
type: 'file',
path: '/entities/users/index.ts',
path: joinFromRoot('entities', 'users', 'index.ts'),
},
],
},
{
type: 'folder',
path: '/entities/posts',
path: joinFromRoot('entities', 'posts'),
children: [
{
type: 'folder',
path: '/entities/posts/ui',
path: joinFromRoot('entities', 'posts', 'ui'),
children: [],
},
{
type: 'file',
path: '/entities/posts/index.ts',
path: joinFromRoot('entities', 'posts', 'index.ts'),
},
],
},
],
},
{
type: 'folder',
path: '/shared',
path: joinFromRoot('shared'),
children: [
{
type: 'folder',
path: '/shared/ui',
path: joinFromRoot('shared', 'ui'),
children: [
{
type: 'file',
path: '/shared/ui/index.ts',
path: joinFromRoot('shared', 'ui', 'index.ts'),
},
{
type: 'file',
path: '/shared/ui/Button.tsx',
path: joinFromRoot('shared', 'ui', 'Button.tsx'),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, it, vi } from 'vitest'
import { join } from 'node:path'

import { compareMessages, parseIntoFsdRoot } from '../_lib/prepare-test.js'
import insignificantSlice from './index.js'
Expand Down Expand Up @@ -122,10 +123,10 @@ it('reports errors on a project with insignificant slices', async () => {

expect((await insignificantSlice.check(root)).diagnostics.sort(compareMessages)).toEqual([
{
message: 'Slice "entities/product" has no references. Consider removing it.',
message: `Slice "${join('entities', 'product')}" has no references. Consider removing it.`,
},
{
message: 'Slice "entities/user" has only one reference in slice "pages/editor". Consider merging them.',
message: `Slice "${join('entities', 'user')}" has only one reference in slice "${join('pages', 'editor')}". Consider merging them.`,
},
])
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, it } from 'vitest'
import { join } from 'node:path'

import noReservedFolderNames from './index.js'
import { parseIntoFsdRoot } from '../_lib/prepare-test.js'
Expand Down Expand Up @@ -43,5 +44,7 @@ it('reports errors on a project with subfolders in segments that use reserved na
`)

const diagnostics = noReservedFolderNames.check(root).diagnostics
expect(diagnostics).toEqual([{ message: 'Folder name "lib" in "shared/ui" is reserved for segment names' }])
expect(diagnostics).toEqual([
{ message: `Folder name "lib" in "${join('shared', 'ui')}" is reserved for segment names` },
])
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, it } from 'vitest'
import { join } from 'node:path'

import noSegmentlessSlices from './index.js'
import { parseIntoFsdRoot } from '../_lib/prepare-test.js'
Expand Down Expand Up @@ -53,6 +54,6 @@ it('reports errors on a project where some slices have no segments', () => {
const diagnostics = noSegmentlessSlices.check(root).diagnostics
expect(diagnostics).toEqual([
{ message: 'Slice "user" on layer "entities" has no segments' },
{ message: 'Slice "settings/profile" on layer "pages" has no segments' },
{ message: `Slice "${join('settings', 'profile')}" on layer "pages" has no segments` },
])
})
8 changes: 4 additions & 4 deletions packages/steiger-plugin-fsd/src/public-api/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, it } from 'vitest'

import publicApi from './index.js'
import { compareMessages, parseIntoFsdRoot } from '../_lib/prepare-test.js'
import { compareMessages, joinFromRoot, parseIntoFsdRoot } from '../_lib/prepare-test.js'

it('reports no errors on a project with all the required public APIs', () => {
const root = parseIntoFsdRoot(`
Expand Down Expand Up @@ -54,7 +54,7 @@ it('reports errors on slices that are missing a public API', () => {
fixes: [
{
type: 'create-file',
path: '/entities/posts/index.ts',
path: joinFromRoot('entities', 'posts', 'index.ts'),
content: '',
},
],
Expand All @@ -64,7 +64,7 @@ it('reports errors on slices that are missing a public API', () => {
fixes: [
{
type: 'create-file',
path: '/pages/editor/index.ts',
path: joinFromRoot('pages', 'editor', 'index.ts'),
content: '',
},
],
Expand Down Expand Up @@ -103,7 +103,7 @@ it('reports errors on segments that are missing a public API', () => {
fixes: [
{
type: 'create-file',
path: '/shared/ui/index.ts',
path: joinFromRoot('shared', 'ui', 'index.ts'),
content: '',
},
],
Expand Down

0 comments on commit eb16c41

Please sign in to comment.