Skip to content
New issue

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

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

Already on GitHub? # to your account

test(tools): increase unit test coverage #810

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
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
47 changes: 44 additions & 3 deletions tools/executors/prettier/check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('check', () => {
return { context, options };
};

describe('errors, no projectName', () => {
describe('errors', () => {
afterEach(() => jest.clearAllMocks());

it('should throw an error if context.projectName is undefined', async () => {
Expand All @@ -64,12 +64,53 @@ describe('check', () => {
expect((<Error>e).message).toEqual('Project name is not defined.');
}
});

it('should throw an error if context.projectName does not exist', async () => {
const { context, options } = setup('does-not-exist');

try {
const result = await check(options, context);
expect(result).not.toMatchObject({ success: true });
} catch (e) {
expect(childProcess.execFileSync).not.toHaveBeenCalledWith('npx', expect.any(Array), {
stdio: 'inherit',
cwd: process.cwd(),
env: process.env,
shell: true,
});
expect((<Error>e).message).toEqual('Project does not exist.');
}
});

it("should throw an error if a project's sourceRoot is undefined", async () => {
const { context, options } = setup('test');

const workspace = context.workspace;
Object.keys(workspace?.projects ?? {}).map(key => {
if (typeof workspace !== 'undefined') {
workspace.projects[key].sourceRoot = void 0;
}
});

try {
const result = await check(options, context);
expect(result).not.toMatchObject({ success: true });
} catch (e) {
expect(childProcess.execFileSync).not.toHaveBeenCalledWith('npx', expect.any(Array), {
stdio: 'inherit',
cwd: process.cwd(),
env: process.env,
shell: true,
});
expect((<Error>e).message).toEqual('Project root does not exist.');
}
});
});

describe('errors, no source directory', () => {
describe('no errors', () => {
afterEach(() => jest.clearAllMocks());

it('should throw an error if source directory does not exist', async () => {
it('should throw an error if a source directory does not exist', async () => {
const { context, options } = setup('test');

try {
Expand Down
47 changes: 44 additions & 3 deletions tools/executors/stylelint/check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('check', () => {
return { context, options };
};

describe('errors, no projectName', () => {
describe('errors: projectName', () => {
afterEach(() => jest.clearAllMocks());

it('should throw an error if context.projectName is undefined', async () => {
Expand All @@ -64,12 +64,53 @@ describe('check', () => {
expect((<Error>e).message).toEqual('Project name is not defined.');
}
});

it('should throw an error if context.projectName does not exist', async () => {
const { context, options } = setup('does-not-exist');

try {
const result = await check(options, context);
expect(result).not.toMatchObject({ success: true });
} catch (e) {
expect(childProcess.execFileSync).not.toHaveBeenCalledWith('npx', expect.any(Array), {
stdio: 'inherit',
cwd: process.cwd(),
env: process.env,
shell: true,
});
expect((<Error>e).message).toEqual('Project does not exist.');
}
});

it("should throw an error if a project's sourceRoot is undefined", async () => {
const { context, options } = setup('test');

const workspace = context.workspace;
Object.keys(workspace?.projects ?? {}).map(key => {
if (typeof workspace !== 'undefined') {
workspace.projects[key].sourceRoot = void 0;
}
});

try {
const result = await check(options, context);
expect(result).not.toMatchObject({ success: true });
} catch (e) {
expect(childProcess.execFileSync).not.toHaveBeenCalledWith('npx', expect.any(Array), {
stdio: 'inherit',
cwd: process.cwd(),
env: process.env,
shell: true,
});
expect((<Error>e).message).toEqual('Project root does not exist.');
}
});
});

describe('errors, no source directory', () => {
describe('no errors', () => {
afterEach(() => jest.clearAllMocks());

it('should throw an error if source directory does not exist', async () => {
it('should throw an error if a source directory does not exist', async () => {
const { context, options } = setup('test');

try {
Expand Down
6 changes: 3 additions & 3 deletions tools/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const config: Config.InitialOptions = {
coverageDirectory: '../coverage/tools',
coverageThreshold: {
global: {
branches: 69,
branches: 71,
functions: 79,
lines: 81,
statements: 80,
lines: 82,
statements: 81,
},
},
displayName: 'tools',
Expand Down