-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(devkit): handle missing
include
and exclude
in tsconfig optio…
…ns when updating tsconfig to support js
- Loading branch information
1 parent
46cac5b
commit cac52fc
Showing
2 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
packages/devkit/src/generators/update-ts-configs-to-js.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,90 @@ | ||
import type { Tree } from 'nx/src/generators/tree'; | ||
import { updateTsConfigsToJs } from './update-ts-configs-to-js'; | ||
import { createTreeWithEmptyWorkspace } from 'nx/src/generators/testing-utils/create-tree-with-empty-workspace'; | ||
|
||
describe('updateTsConfigsToJs', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should set allowJs to true in tsconfig.json', () => { | ||
tree.write('tsconfig.json', `{}`); | ||
tree.write('tsconfig.lib.json', `{}`); | ||
|
||
updateTsConfigsToJs(tree, { projectRoot: '.' }); | ||
|
||
expect(tree.read('tsconfig.json', 'utf-8')).toMatchInlineSnapshot(` | ||
"{ | ||
"compilerOptions": { | ||
"allowJs": true | ||
} | ||
} | ||
" | ||
`); | ||
}); | ||
|
||
it.each` | ||
tsconfig | ||
${'tsconfig.app.json'} | ||
${'tsconfig.lib.json'} | ||
`( | ||
'should add the relevant include and exclude to $tsconfig', | ||
({ tsconfig }) => { | ||
tree.write('tsconfig.json', `{}`); | ||
tree.write( | ||
tsconfig, | ||
JSON.stringify({ | ||
include: ['src/**/*.ts'], | ||
exclude: ['src/**/*.spec.ts', 'src/**/*.test.ts'], | ||
}) | ||
); | ||
|
||
updateTsConfigsToJs(tree, { projectRoot: '.' }); | ||
|
||
expect(tree.read(tsconfig, 'utf-8')).toMatchInlineSnapshot(` | ||
"{ | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.js" | ||
], | ||
"exclude": [ | ||
"src/**/*.spec.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.js", | ||
"src/**/*.test.js" | ||
] | ||
} | ||
" | ||
`); | ||
} | ||
); | ||
|
||
it.each` | ||
tsconfig | ||
${'tsconfig.app.json'} | ||
${'tsconfig.lib.json'} | ||
`( | ||
'should update $tsconfig with the relevant include and exclude when those properties are not defined', | ||
({ tsconfig }) => { | ||
tree.write('tsconfig.json', `{}`); | ||
tree.write(tsconfig, `{}`); | ||
|
||
updateTsConfigsToJs(tree, { projectRoot: '.' }); | ||
|
||
expect(tree.read(tsconfig, 'utf-8')).toMatchInlineSnapshot(` | ||
"{ | ||
"include": [ | ||
"src/**/*.js" | ||
], | ||
"exclude": [ | ||
"src/**/*.spec.js", | ||
"src/**/*.test.js" | ||
] | ||
} | ||
" | ||
`); | ||
} | ||
); | ||
}); |
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