Skip to content

Commit

Permalink
test: add test cases for handling commented lines
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Nov 4, 2024
1 parent b40d79c commit cd6e58a
Showing 1 changed file with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,75 @@ const packageJsonWithoutCodegenConfig = `
}
`;

const buildGradleWithSingleLineComments = `
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
// react {
// libraryName = "justalibrary"
// }
`;

const buildGradleWithMultiLineComments = `
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
/*
react {
libraryName = "justalibrary"
}
*/
`;

const buildGradleValidWithComments = `
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
// react {
// libraryName = "justalibrary"
// }
react {
libraryName = "justalibrary2"
}
`;

const buildGradleKtsWithSingleLineComments = `
apply(id = "com.android.application")
apply(id = "com.facebook.react")
// react {
// libraryName.set("justalibrary")
// }
`;

const buildGradleKtsWithMultiLineComments = `
apply(id = "com.android.application")
apply(id = "com.facebook.react")
/*
react {
libraryName.set("justalibrary")
}
*/
`;

describe('android::findLibraryName', () => {
beforeAll(() => {
fs.__setMockFilesystem({
empty: {},
empty: {
singlelinecomments: {
'build.gradle': buildGradleWithSingleLineComments,
},
multilinecomments: {
'build.gradle': buildGradleWithMultiLineComments,
},
singllinecommentskts: {
'build.gradle.kts': buildGradleKtsWithSingleLineComments,
},
multilinecommentskts: {
'build.gradle.kts': buildGradleKtsWithMultiLineComments,
},
},
valid: {
android: mocks.valid,
singlequotes: {
Expand All @@ -73,6 +138,9 @@ describe('android::findLibraryName', () => {
'build.gradle': buildGradleWithSingleQuotes,
},
},
withcomments: {
'build.gradle': buildGradleValidWithComments,
},
},
});
});
Expand All @@ -98,6 +166,10 @@ describe('android::findLibraryName', () => {
).toBe('my-awesome-library');
});

it('returns the library name if declared in the build.gradle file with comments', () => {
expect(findLibraryName('/', '/valid/withcomments')).toBe('justalibrary2');
});

it('falls back to reading from build.gradle when codegenConfig is not there', () => {
expect(
findLibraryName(
Expand All @@ -110,4 +182,20 @@ describe('android::findLibraryName', () => {
it('returns null if there is no build.gradle file', () => {
expect(findLibraryName('/', '/empty')).toBeUndefined();
});

it('returns null if the library name is declared as a single line comment', () => {
expect(findLibraryName('/', '/empty/singlelinecomments')).toBeUndefined();
});

it('returns null if the library name is declared as a multi line comment', () => {
expect(findLibraryName('/', '/empty/multilinecomments')).toBeUndefined();
});

it('returns null if the library name is declared as a single line comment in build.gradle.kts', () => {
expect(findLibraryName('/', '/empty/singllinecommentskts')).toBeUndefined();
});

it('returns null if the library name is declared as a multi line comment in build.gradle.kts', () => {
expect(findLibraryName('/', '/empty/multilinecommentskts')).toBeUndefined();
});
});

0 comments on commit cd6e58a

Please sign in to comment.