|
6 | 6 | readJson,
|
7 | 7 | Tree,
|
8 | 8 | updateJson,
|
| 9 | + writeJson, |
9 | 10 | } from '@nx/devkit';
|
10 | 11 | import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
11 | 12 | import {
|
@@ -70,10 +71,24 @@ describe('@nx/eslint:workspace-rules-project', () => {
|
70 | 71 | expect(tsConfig.extends).toBe('../../tsconfig.json');
|
71 | 72 | });
|
72 | 73 |
|
73 |
| - it('should create a project with a test target', async () => { |
| 74 | + it('should create the jest config using ts-jest', async () => { |
74 | 75 | await lintWorkspaceRulesProjectGenerator(tree);
|
75 | 76 |
|
76 | 77 | expect(tree.exists('tools/eslint-rules/jest.config.ts')).toBeTruthy();
|
| 78 | + expect(tree.read('tools/eslint-rules/jest.config.ts', 'utf-8')) |
| 79 | + .toMatchInlineSnapshot(` |
| 80 | + "export default { |
| 81 | + displayName: 'eslint-rules', |
| 82 | + preset: '../../jest.preset.js', |
| 83 | + transform: { |
| 84 | + '^.+\\\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], |
| 85 | + }, |
| 86 | + moduleFileExtensions: ['ts', 'js', 'html'], |
| 87 | + coverageDirectory: '../../coverage/tools/eslint-rules', |
| 88 | + }; |
| 89 | + " |
| 90 | + `); |
| 91 | + expect(tree.exists('tools/eslint-rules/.spec.swcrc')).toBeFalsy(); |
77 | 92 | });
|
78 | 93 |
|
79 | 94 | it('should not update the required files if the project already exists', async () => {
|
@@ -104,4 +119,79 @@ describe('@nx/eslint:workspace-rules-project', () => {
|
104 | 119 | customTsconfigContents
|
105 | 120 | );
|
106 | 121 | });
|
| 122 | + |
| 123 | + describe('TS solution setup', () => { |
| 124 | + beforeEach(() => { |
| 125 | + tree = createTreeWithEmptyWorkspace(); |
| 126 | + updateJson(tree, 'package.json', (json) => { |
| 127 | + json.workspaces = ['packages/*']; |
| 128 | + return json; |
| 129 | + }); |
| 130 | + writeJson(tree, 'tsconfig.base.json', { |
| 131 | + compilerOptions: { composite: true }, |
| 132 | + }); |
| 133 | + writeJson(tree, 'tsconfig.json', { |
| 134 | + extends: './tsconfig.base.json', |
| 135 | + files: [], |
| 136 | + references: [], |
| 137 | + }); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should create the jest config using @swc/jest', async () => { |
| 141 | + await lintWorkspaceRulesProjectGenerator(tree); |
| 142 | + |
| 143 | + expect(tree.exists('tools/eslint-rules/jest.config.ts')).toBeTruthy(); |
| 144 | + expect(tree.read('tools/eslint-rules/jest.config.ts', 'utf-8')) |
| 145 | + .toMatchInlineSnapshot(` |
| 146 | + "/* eslint-disable */ |
| 147 | + import { readFileSync } from 'fs'; |
| 148 | +
|
| 149 | + // Reading the SWC compilation config for the spec files |
| 150 | + const swcJestConfig = JSON.parse( |
| 151 | + readFileSync(\`\${__dirname}/.spec.swcrc\`, 'utf-8') |
| 152 | + ); |
| 153 | +
|
| 154 | + // Disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves |
| 155 | + swcJestConfig.swcrc = false; |
| 156 | +
|
| 157 | + export default { |
| 158 | + displayName: 'eslint-rules', |
| 159 | + preset: '../../jest.preset.js', |
| 160 | + transform: { |
| 161 | + '^.+\\\\.[tj]s$': ['@swc/jest', swcJestConfig], |
| 162 | + }, |
| 163 | + moduleFileExtensions: ['ts', 'js', 'html'], |
| 164 | + coverageDirectory: 'test-output/jest/coverage', |
| 165 | + }; |
| 166 | + " |
| 167 | + `); |
| 168 | + expect(tree.exists('tools/eslint-rules/.spec.swcrc')).toBeTruthy(); |
| 169 | + expect(tree.read('tools/eslint-rules/.spec.swcrc', 'utf-8')) |
| 170 | + .toMatchInlineSnapshot(` |
| 171 | + "{ |
| 172 | + "jsc": { |
| 173 | + "target": "es2017", |
| 174 | + "parser": { |
| 175 | + "syntax": "typescript", |
| 176 | + "decorators": true, |
| 177 | + "dynamicImport": true |
| 178 | + }, |
| 179 | + "transform": { |
| 180 | + "decoratorMetadata": true, |
| 181 | + "legacyDecorator": true |
| 182 | + }, |
| 183 | + "keepClassNames": true, |
| 184 | + "externalHelpers": true, |
| 185 | + "loose": true |
| 186 | + }, |
| 187 | + "module": { |
| 188 | + "type": "es6" |
| 189 | + }, |
| 190 | + "sourceMaps": true, |
| 191 | + "exclude": [] |
| 192 | + } |
| 193 | + " |
| 194 | + `); |
| 195 | + }); |
| 196 | + }); |
107 | 197 | });
|
0 commit comments