-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): add test-setup.ts to ignored prod inputs (#17918)
- Loading branch information
Showing
5 changed files
with
89 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
packages/jest/src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore.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,51 @@ | ||
import { Tree, readNxJson, updateNxJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import addTestSetupToIgnoredInputs from './add-test-setup-to-inputs-ignore'; | ||
|
||
describe('Jest Migration - jest 29 mocked usage in tests', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
}); | ||
|
||
it('should add inputs configuration for test-setup if missing', async () => { | ||
updateNxJson(tree, { | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*', 'sharedGlobals'], | ||
sharedGlobals: [], | ||
production: ['default'], | ||
}, | ||
}); | ||
|
||
await addTestSetupToIgnoredInputs(tree); | ||
|
||
const updated = readNxJson(tree); | ||
expect(updated.namedInputs.production).toMatchInlineSnapshot(` | ||
[ | ||
"default", | ||
"!{projectRoot}/src/test-setup.[jt]s", | ||
] | ||
`); | ||
}); | ||
|
||
it('should not add inputs configuration for test-setup if existing', async () => { | ||
updateNxJson(tree, { | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*', 'sharedGlobals'], | ||
sharedGlobals: [], | ||
production: ['!{projectRoot}/src/test-setup.[jt]s', 'default'], | ||
}, | ||
}); | ||
|
||
await addTestSetupToIgnoredInputs(tree); | ||
|
||
const updated = readNxJson(tree); | ||
expect(updated.namedInputs.production).toMatchInlineSnapshot(` | ||
[ | ||
"!{projectRoot}/src/test-setup.[jt]s", | ||
"default", | ||
] | ||
`); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/jest/src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore.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,28 @@ | ||
import { | ||
NxJsonConfiguration, | ||
Tree, | ||
formatFiles, | ||
readNxJson, | ||
updateNxJson, | ||
} from '@nx/devkit'; | ||
|
||
export async function addTestSetupToIgnoredInputs(tree: Tree) { | ||
const nxJson: NxJsonConfiguration = readNxJson(tree); | ||
|
||
if (!nxJson) { | ||
return; | ||
} | ||
if ( | ||
nxJson.namedInputs?.production && | ||
!nxJson.namedInputs.production.includes( | ||
'!{projectRoot}/src/test-setup.[jt]s' | ||
) | ||
) { | ||
nxJson.namedInputs.production.push('!{projectRoot}/src/test-setup.[jt]s'); | ||
updateNxJson(tree, nxJson); | ||
} | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default addTestSetupToIgnoredInputs; |
8f0ec5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app