Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix unitest in windows #19

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions @lib/util-lib/__tests__/finder/findWorkspaceProject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { vol } from 'memfs'
import { findWorkspaceProject, PROJECT_CACHE } from '@/finder/findWorkspaceProject'
import path from 'path'

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
jest.mock('fs', () => jest.requireActual<typeof import('memfs')>('memfs'))
Expand All @@ -12,26 +13,26 @@ describe('finder/findWorkspaceProject', () => {

it('should find projects from a workspace', async () => {
vol.fromJSON({
'package.json': JSON.stringify({
[path.join('package.json')]: JSON.stringify({
workspaces: ['packages/*'],
}),
'packages/package-a/package.json': JSON.stringify({
[path.join('packages/package-a/package.json')]: JSON.stringify({
name: 'package-a',
version: '1.0.0',
description: 'Package A',
dependencies: {
'package-b': '^1.0.0',
},
}),
'packages/package-b/package.json': JSON.stringify({
[path.join('packages/package-b/package.json')]: JSON.stringify({
name: 'package-b',
version: '1.0.0',
description: 'Package B',
dependencies: {
'package-c': '^1.0.0',
},
}),
'packages/package-c/package.json': JSON.stringify({
[path.join('packages/package-c/package.json')]: JSON.stringify({
name: 'package-c',
version: '1.0.0',
description: 'Package C',
Expand All @@ -49,7 +50,7 @@ describe('finder/findWorkspaceProject', () => {
version: '1.0.0',
description: 'Package C',
isPrivate: false,
location: 'packages/package-c',
location: path.join('packages/package-c'),
dependencies: [],
workspaceDependencies: [],
},
Expand All @@ -58,7 +59,7 @@ describe('finder/findWorkspaceProject', () => {
version: '1.0.0',
description: 'Package B',
isPrivate: false,
location: 'packages/package-b',
location: path.join('packages/package-b'),
dependencies: ['package-c'],
workspaceDependencies: ['package-c'],
},
Expand All @@ -67,7 +68,7 @@ describe('finder/findWorkspaceProject', () => {
version: '1.0.0',
description: 'Package A',
isPrivate: false,
location: 'packages/package-a',
location: path.join('packages/package-a'),
dependencies: ['package-b'],
workspaceDependencies: ['package-b'],
},
Expand All @@ -76,26 +77,26 @@ describe('finder/findWorkspaceProject', () => {

it('should find projects from a workspace with a custom pattern', async () => {
vol.fromJSON({
'package.json': JSON.stringify({
[path.join('package.json')]: JSON.stringify({
workspaces: ['packages/*'],
}),
'packages/package-a/package.json': JSON.stringify({
[path.join('packages/package-a/package.json')]: JSON.stringify({
name: 'package-a',
version: '1.0.0',
description: 'Package A',
dependencies: {
'package-b': '^1.0.0',
},
}),
'packages/package-b/package.json': JSON.stringify({
[path.join('packages/package-b/package.json')]: JSON.stringify({
name: 'package-b',
version: '1.0.0',
description: 'Package B',
dependencies: {
'package-c': '^1.0.0',
},
}),
'packages/package-c/package.json': JSON.stringify({
[path.join('packages/package-c/package.json')]: JSON.stringify({
name: 'package-c',
version: '1.0.0',
description: 'Package C',
Expand All @@ -114,7 +115,7 @@ describe('finder/findWorkspaceProject', () => {
version: '1.0.0',
description: 'Package A',
isPrivate: false,
location: 'packages/package-a',
location: path.join('packages/package-a'),
dependencies: ['package-b'],
workspaceDependencies: [],
},
Expand All @@ -123,26 +124,26 @@ describe('finder/findWorkspaceProject', () => {

it('should find projects from a workspace with a custom pattern and cwd, and from cache', async () => {
vol.fromJSON({
'package.json': JSON.stringify({
[path.join('package.json')]: JSON.stringify({
workspaces: ['packages/*'],
}),
'packages/package-a/package.json': JSON.stringify({
[path.join('packages/package-a/package.json')]: JSON.stringify({
name: 'package-a',
version: '1.0.0',
description: 'Package A',
dependencies: {
'package-b': '^1.0.0',
},
}),
'packages/package-b/package.json': JSON.stringify({
[path.join('packages/package-b/package.json')]: JSON.stringify({
name: 'package-b',
version: '1.0.0',
description: 'Package B',
dependencies: {
'package-c': '^1.0.0',
},
}),
'packages/package-c/package.json': JSON.stringify({
[path.join('packages/package-c/package.json')]: JSON.stringify({
name: 'package-c',
version: '1.0.0',
description: 'Package C',
Expand All @@ -161,18 +162,18 @@ describe('finder/findWorkspaceProject', () => {

it('should throw an error if a project name is duplicated in the workspace', async () => {
vol.fromJSON({
'package.json': JSON.stringify({
[path.join('package.json')]: JSON.stringify({
workspaces: ['packages/*'],
}),
'packages/package-a/package.json': JSON.stringify({
[path.join('packages/package-a/package.json')]: JSON.stringify({
name: 'package-a',
version: '1.0.0',
description: 'Package A',
dependencies: {
'package-b': '^1.0.0',
},
}),
'packages/package-b/package.json': JSON.stringify({
[path.join('packages/package-b/package.json')]: JSON.stringify({
name: 'package-a',
version: '1.0.0',
description: 'Package A',
Expand All @@ -187,6 +188,6 @@ describe('finder/findWorkspaceProject', () => {
pattern: ['packages/*'],
cwd: '',
})
).rejects.toThrow('The project name package-a is duplicated in the workspace.\n - packages/package-b/package.json\n - packages/package-a/package.json')
).rejects.toThrow(`The project name package-a is duplicated in the workspace.\n - ${path.join('packages/package-b/package.json')}\n - ${path.join('packages/package-a/package.json')}`)
})
})
Loading