Skip to content

Commit

Permalink
fix: allow applying other front module after vitest config being form…
Browse files Browse the repository at this point in the history
…atted with prettier

related to #11106
  • Loading branch information
murdos committed Oct 23, 2024
1 parent a3b34e7 commit 800f4df
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ private Consumer<JHipsterModuleBuilder> patchVitestConfig(JHipsterModuleProperti
.add(lineAfterRegex("from 'vitest/config';"), "import react from '@vitejs/plugin-react';")
.add(text("plugins: ["), "plugins: [react(), ")
.add(text("environment: 'node',"), "environment: 'jsdom',")
.add(vitestCoverageExclusion(properties,"src/main/webapp/app/index.tsx"))
.add(vitestCoverageExclusion(properties,"src/main/webapp/app/injections.ts"))
.add(vitestCoverageExclusion("src/main/webapp/app/index.tsx"))
.add(vitestCoverageExclusion("src/main/webapp/app/injections.ts"))
.and();
//@formatter:on
}

private static MandatoryReplacer vitestCoverageExclusion(JHipsterModuleProperties properties, String filePattern) {
Indentation indentation = properties.indentation();
return new MandatoryReplacer(lineAfterRegex("configDefaults.coverage.exclude"), indentation.times(4) + "'" + filePattern + "',");
private static MandatoryReplacer vitestCoverageExclusion(String filePattern) {
return new MandatoryReplacer(
text("(configDefaults.coverage.exclude as string[])"),
"(configDefaults.coverage.exclude as string[])" + ", '" + filePattern + "'"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,19 @@ private Consumer<JHipsterModuleBuilder> patchVitestConfig(JHipsterModuleProperti
.add(lineAfterRegex("from 'vitest/config';"), "import vue from '@vitejs/plugin-vue';")
.add(text("plugins: ["), "plugins: [vue(), ")
.add(text("environment: 'node',"), "environment: 'jsdom',")
.add(vitestCoverageExclusion(properties,"src/main/webapp/**/*.component.ts"))
.add(vitestCoverageExclusion(properties,"src/main/webapp/app/router.ts"))
.add(vitestCoverageExclusion(properties,"src/main/webapp/app/injections.ts"))
.add(vitestCoverageExclusion(properties,"src/main/webapp/app/main.ts"))
.add(vitestCoverageExclusion("src/main/webapp/**/*.component.ts"))
.add(vitestCoverageExclusion("src/main/webapp/app/router.ts"))
.add(vitestCoverageExclusion("src/main/webapp/app/injections.ts"))
.add(vitestCoverageExclusion("src/main/webapp/app/main.ts"))
.and();
//@formatter:on
}

private static MandatoryReplacer vitestCoverageExclusion(JHipsterModuleProperties properties, String filePattern) {
Indentation indentation = properties.indentation();
return new MandatoryReplacer(lineAfterRegex("configDefaults.coverage.exclude"), indentation.times(4) + "'" + filePattern + "',");
private static MandatoryReplacer vitestCoverageExclusion(String filePattern) {
return new MandatoryReplacer(
text("(configDefaults.coverage.exclude as string[])"),
"(configDefaults.coverage.exclude as string[])" + ", '" + filePattern + "'"
);
}

public JHipsterModule buildPiniaModule(JHipsterModuleProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export default defineConfig({
100: true,
},
include: ['src/main/webapp/**/*.ts?(x)'],
exclude: [
...configDefaults.coverage.exclude as string[],
],
exclude: [...(configDefaults.coverage.exclude as string[])],
provider: 'istanbul',
reportsDirectory: '{{projectBuildDirectory}}/test-results/',
reporter: ['html', 'json-summary', 'text', 'text-summary', 'lcov', 'clover'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void shouldCreateVueModule() {
"""
)
.and()
.hasPrefixedFiles("", "eslint.config.js", "tsconfig.build.json", "vite.config.ts", "vitest.config.ts")
.hasPrefixedFiles("", "eslint.config.js", "tsconfig.build.json", "vite.config.ts")
.hasFile("tsconfig.json")
.matchingSavedSnapshot()
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export default defineConfig({
100: true,
},
include: ['src/main/webapp/**/*.ts?(x)'],
exclude: [
...configDefaults.coverage.exclude as string[],
'src/main/webapp/app/injections.ts',
'src/main/webapp/app/index.tsx',
],
exclude: [...(configDefaults.coverage.exclude as string[]), 'src/main/webapp/app/injections.ts', 'src/main/webapp/app/index.tsx'],
provider: 'istanbul',
reportsDirectory: 'target/test-results/',
reporter: ['html', 'json-summary', 'text', 'text-summary', 'lcov', 'clover'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ export default defineConfig({
100: true,
},
include: ['src/main/webapp/**/*.ts?(x)'],
exclude: [
...configDefaults.coverage.exclude as string[],
'src/main/webapp/app/main.ts',
'src/main/webapp/app/injections.ts',
'src/main/webapp/app/router.ts',
'src/main/webapp/**/*.component.ts',
],
exclude: [...(configDefaults.coverage.exclude as string[]), 'src/main/webapp/app/main.ts', 'src/main/webapp/app/injections.ts', 'src/main/webapp/app/router.ts', 'src/main/webapp/**/*.component.ts'],
provider: 'istanbul',
reportsDirectory: 'target/test-results/',
reporter: ['html', 'json-summary', 'text', 'text-summary', 'lcov', 'clover'],
Expand Down

0 comments on commit 800f4df

Please sign in to comment.