Skip to content
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
15 changes: 13 additions & 2 deletions packages/local-cli/link/__fixtures__/android/patchedBuild.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
*/

dependencies {
implementation project(':test')
implementation(project(':test2')) {
implementation project(':test-impl')
implementation(project(':test-impl-config')) {
exclude(group: 'org.unwanted', module: 'test10')
}
implementation (project(':test-impl-config-spaces')) {
exclude group: 'com.google.android.gms'
}
// Indentation being off for some entries is a part of the test, because
// Gradle doesn't care about indentation and neither should we
implementationDebug project(':test-impl-debug')
implementationAbc project(':test-impl-abc')
compile project(':test-compile')
compileDebug project(':test-compile-debug')
compileAbc project(':test-compile-abc')

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.facebook.react:react-native:+"
Expand Down
23 changes: 16 additions & 7 deletions packages/local-cli/link/__tests__/android/isInstalled-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ const projectConfig = {
};

describe('android::isInstalled', () => {
it('should return true when project is already in build.gradle', () => {
expect(isInstalled(projectConfig, 'test')).toBeTruthy();
expect(isInstalled(projectConfig, 'test2')).toBeTruthy();
});

it('should return false when project is not in build.gradle', () =>
expect(isInstalled(projectConfig, 'test3')).toBeFalsy());
test.each([
['test-impl', true],
['test-impl-config', true],
['test-impl-config-spaces', true],
['test-impl-debug', true],
['test-impl-abc', true],
['test-compile', true],
['test-compile-debug', true],
['test-compile-abc', true],
['test-not-there-yet', false],
])(
Copy link
Member

Choose a reason for hiding this comment

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

dope

'properly detects if %p project is already in build.gradle',
(project, isPresent) => {
expect(isInstalled(projectConfig, project)).toBe(isPresent);
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ describe('makeBuildPatch', () => {

it('should make a correct install check pattern', () => {
const { installPattern } = makeBuildPatch(name);
const match = `/\\s{4}(implementation)(\\(|\\s)(project)\\(\\':${name}\\'\\)(\\)|\\s)/`;
expect(installPattern.toString()).toBe(match);
expect(installPattern.toString()).toEqual(expect.stringContaining(name));
});
});

Expand All @@ -44,7 +43,8 @@ describe('makeBuildPatchWithScopedPackage', () => {

it('should make a correct install check pattern', () => {
const { installPattern } = makeBuildPatch(scopedName);
const match = `/\\s{4}(implementation)(\\(|\\s)(project)\\(\\':${normalizedScopedName}\\'\\)(\\)|\\s)/`;
expect(installPattern.toString()).toBe(match);
expect(installPattern.toString()).toEqual(
expect.stringContaining(normalizedScopedName)
);
});
});
5 changes: 1 addition & 4 deletions packages/local-cli/link/__tests__/link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* @emails oncall+javascript_foundation
*/

const log = require('npmlog');

jest.mock('npmlog');
jest.setMock('chalk', { grey: str => str });

const context = {
Expand All @@ -19,8 +18,6 @@ const context = {
describe('link', () => {
beforeEach(() => {
jest.resetModules();
delete require.cache[require.resolve('../link')];
log.level = 'silent';
});

it('should reject when run in a folder without package.json', done => {
Expand Down
2 changes: 1 addition & 1 deletion packages/local-cli/link/android/patches/makeBuildPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const normalizeProjectName = require('./normalizeProjectName');
module.exports = function makeBuildPatch(name) {
const normalizedProjectName = normalizeProjectName(name);
const installPattern = new RegExp(
`\\s{4}(implementation)(\\(|\\s)(project)\\(\\':${normalizedProjectName}\\'\\)(\\)|\\s)`
`(implementation|compile)\\w*\\s*\\(*project\\(['"]:${normalizedProjectName}['"]\\)`
);

return {
Expand Down