-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gradle): fix gradle exclude src/test
- Loading branch information
Showing
5 changed files
with
109 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/gradle/src/migrations/19-4-1/change-regex-test-production.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Tree, readNxJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import update from './change-regex-test-production'; | ||
|
||
describe('change-regex-test-production', () => { | ||
let tree: Tree; | ||
|
||
beforeAll(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should not add to the namedInputs if it does not exist', async () => { | ||
tree.write( | ||
'nx.json', | ||
JSON.stringify({ namedInputs: {}, plugins: ['@nx/gradle'] }) | ||
); | ||
update(tree); | ||
expect(readNxJson(tree)).toMatchInlineSnapshot(` | ||
{ | ||
"namedInputs": {}, | ||
"plugins": [ | ||
"@nx/gradle", | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('should not add to the namedInputs production if it is empty', async () => { | ||
tree.write( | ||
'nx.json', | ||
JSON.stringify({ | ||
namedInputs: { production: [] }, | ||
plugins: ['@nx/gradle'], | ||
}) | ||
); | ||
update(tree); | ||
expect(readNxJson(tree)).toMatchInlineSnapshot(` | ||
{ | ||
"namedInputs": { | ||
"production": [], | ||
}, | ||
"plugins": [ | ||
"@nx/gradle", | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('should remove !{projectRoot}/test/**/* from the namedInputs production', async () => { | ||
tree.write( | ||
'nx.json', | ||
JSON.stringify({ | ||
namedInputs: { production: ['!{projectRoot}/test/**/*'] }, | ||
plugins: ['@nx/gradle'], | ||
}) | ||
); | ||
update(tree); | ||
expect(readNxJson(tree)).toMatchInlineSnapshot(` | ||
{ | ||
"namedInputs": { | ||
"production": [ | ||
"!{projectRoot}/src/test/**/*", | ||
], | ||
}, | ||
"plugins": [ | ||
"@nx/gradle", | ||
], | ||
} | ||
`); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/gradle/src/migrations/19-4-1/change-regex-test-production.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Tree, readNxJson } from '@nx/devkit'; | ||
import { hasGradlePlugin } from '../../utils/has-gradle-plugin'; | ||
|
||
// This function changes !{projectRoot}/test/**/* in nx.json for production to !{projectRoot}/src/test/**/* | ||
export default function update(tree: Tree) { | ||
if (!hasGradlePlugin(tree)) { | ||
return; | ||
} | ||
if (tree.exists('nx.json')) { | ||
const nxJson = readNxJson(tree); | ||
const production = nxJson?.namedInputs?.production; | ||
if (production?.includes('!{projectRoot}/test/**/*')) { | ||
production[production.indexOf('!{projectRoot}/test/**/*')] = | ||
'!{projectRoot}/src/test/**/*'; | ||
tree.write('nx.json', JSON.stringify(nxJson, null, 2)); | ||
} | ||
} | ||
} |