-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test for current state of the
verifyWorkspaceDependencies
ch…
…eck (#2144) * Create test for current state of the `verifyWorkspaceDependencies` check
- Loading branch information
Showing
7 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
__fixtures__/verifiable-project/other-packages/package-four/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "package-four", | ||
"private": true, | ||
"modular": { | ||
"type": "esm-view" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "verifiable-project", | ||
"version": "1.0.0", | ||
"author": "App Frameworks team", | ||
"license": "MIT", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/**", | ||
"other-packages/**" | ||
], | ||
"modular": { | ||
"type": "root" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.21" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
__fixtures__/verifiable-project/packages/app-one/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "app-one", | ||
"private": true, | ||
"modular": { | ||
"type": "app" | ||
}, | ||
"dependencies": { | ||
"package-one": "workspace:*", | ||
"package-two": "workspace:^", | ||
"package-three": "workspace:~", | ||
"package-four": "workspace:^1.0.0" | ||
}, | ||
"version": "1.0.0" | ||
} |
9 changes: 9 additions & 0 deletions
9
__fixtures__/verifiable-project/packages/package-one/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "package-one", | ||
"private": true, | ||
"modular": { | ||
"type": "package" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0" | ||
} |
6 changes: 6 additions & 0 deletions
6
__fixtures__/verifiable-project/packages/package-three/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "package-three", | ||
"private": true, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0" | ||
} |
9 changes: 9 additions & 0 deletions
9
__fixtures__/verifiable-project/packages/package-two/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "package-two", | ||
"private": true, | ||
"modular": { | ||
"type": "package" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0" | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/modular-scripts/src/__tests__/check/verifyWorkspaceDependencies.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { check } from '../../check/verifyWorkspaceDependencies'; | ||
import getModularRoot from '../../utils/getModularRoot'; | ||
import { error } from '../../utils/logger'; | ||
|
||
jest.mock('../../utils/getModularRoot', () => jest.fn()); | ||
jest.mock('../../utils/logger', () => ({ | ||
error: jest.fn(), | ||
debug: jest.fn(), | ||
})); | ||
|
||
describe('verifyWorkspaceDependencies', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('checks a valid workspace', async () => { | ||
mock(getModularRoot).mockReturnValue( | ||
'__fixtures__/resolve-workspace/clean-workspace-1', | ||
); | ||
|
||
expect(await check()).toBe(true); | ||
expect(error).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('rejects packages not in the "packages" directory', async () => { | ||
mock(getModularRoot).mockReturnValue('__fixtures__/verifiable-project'); | ||
|
||
const checked = await check('__fixtures__/verifiable-project'); | ||
expect(checked).toBe(false); | ||
expect(error).toHaveBeenCalledWith( | ||
expect.stringContaining( | ||
`package-four is not located within the "/packages" directory`, | ||
), | ||
); | ||
}); | ||
}); | ||
|
||
function mock(input: unknown) { | ||
return input as jest.Mock; | ||
} |