Skip to content

Commit

Permalink
Create test for current state of the verifyWorkspaceDependencies ch…
Browse files Browse the repository at this point in the history
…eck (#2144)

* Create test for current state of the `verifyWorkspaceDependencies` check
  • Loading branch information
steveukx authored Sep 15, 2022
1 parent deaee2c commit 1287b1b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
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"
}
17 changes: 17 additions & 0 deletions __fixtures__/verifiable-project/package.json
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 __fixtures__/verifiable-project/packages/app-one/package.json
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"
}
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"
}
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"
}
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"
}
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;
}

0 comments on commit 1287b1b

Please sign in to comment.