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

feat(core): add affected projects by test suffixes #25

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
73 changes: 72 additions & 1 deletion libs/core/src/true-affected.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,43 @@ describe('trueAffected', () => {
expect(affected).toEqual(['proj1', 'proj3']);
});

it('should ignore files that are not in projects files', async () => {
it('should include test files by suffixes', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
filePath: 'proj1/index._test_.ts',
changedLines: [6],
},
]);

const affected = await trueAffected({
cwd,
base: 'main',
rootTsConfig: 'tsconfig.json',
projects: [
{
name: 'proj1',
sourceRoot: 'proj1/',
tsConfig: 'proj1/tsconfig.json',
},
{
name: 'proj2',
sourceRoot: 'proj2/',
tsConfig: 'proj2/tsconfig.json',
},
{
name: 'proj3',
sourceRoot: 'proj3/',
tsConfig: 'proj3/tsconfig.json',
implicitDependencies: ['proj1'],
},
],
testSuffixes: ['_test_'],
});

expect(affected).toEqual(['proj1', 'proj3']);
});

it('should default test files suffixes to spec and test', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
filePath: 'proj1/index.spec.ts',
Expand Down Expand Up @@ -197,6 +233,41 @@ describe('trueAffected', () => {
],
});

expect(affected).toEqual(['proj1', 'proj3']);
});

it('should ignore files that are not in projects files', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
filePath: 'proj1/README.md',
changedLines: [6],
},
]);

const affected = await trueAffected({
cwd,
base: 'main',
rootTsConfig: 'tsconfig.json',
projects: [
{
name: 'proj1',
sourceRoot: 'proj1/',
tsConfig: 'proj1/tsconfig.json',
},
{
name: 'proj2',
sourceRoot: 'proj2/',
tsConfig: 'proj2/tsconfig.json',
},
{
name: 'proj3',
sourceRoot: 'proj3/',
tsConfig: 'proj3/tsconfig.json',
implicitDependencies: ['proj1'],
},
],
});

expect(affected).toEqual([]);
});

Expand Down
10 changes: 9 additions & 1 deletion libs/core/src/true-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const trueAffected = async ({
base = 'origin/main',
projects,
includeFiles = [],
testSuffixes = ['spec', 'test'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that only tests are things that can create this problem? What about types? Or bin files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start with these, and later improve by requirements.
Also I'd give control from the cli of its required

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what i am saying is that maybe the name of the option (testSuffixes) is wrong

}: TrueAffected) => {
const project = new Project({
compilerOptions: {
Expand Down Expand Up @@ -88,7 +89,14 @@ export const trueAffected = async ({

const changedFiles = [...sourceChangedFiles, ...nonSourceChangedFiles];

const affectedPackages = new Set<string>();
const changedTestFilesPackages = changedFiles
.filter(({ filePath }) =>
new RegExp(`.*\\.(${testSuffixes.join('|')})\\.(ts|js)x?$`).test(filePath)
)
.map(({ filePath }) => getPackageNameByPath(filePath, projects))
.filter((v): v is string => v != null);

const affectedPackages = new Set<string>(changedTestFilesPackages);
const visitedIdentifiers = new Map<string, string[]>();

const findReferencesLibs = (node: Node<ts.Node>) => {
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface TrueAffected {
base?: string;
projects: TrueAffectedProject[];
includeFiles?: string[];
testSuffixes?: string[];
}
Loading