Skip to content

Commit

Permalink
feat(vue): patch vitest config file from typescript module rather tha…
Browse files Browse the repository at this point in the history
…n overwriting it
  • Loading branch information
murdos committed Sep 14, 2024
1 parent 8d6a4db commit bc8e287
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public JHipsterModule buildVueModule(JHipsterModuleProperties properties) {
.add(SOURCE.file("tsconfig.build.json"), to("tsconfig.build.json"))
.batch(SOURCE, to("."))
.addTemplate("vite.config.ts")
.addTemplate("vitest.config.ts")
.and()
.add(SOURCE.template("webapp/index.html"), to("src/main/webapp/index.html"))
.batch(APP_SOURCE, MAIN_DESTINATION)
Expand All @@ -98,6 +97,7 @@ public JHipsterModule buildVueModule(JHipsterModuleProperties properties) {
.add(APP_SOURCE.template("test/webapp/unit/router/infrastructure/primary/HomeRouter.spec.ts.mustache"), TEST_DESTINATION.append("unit/router/infrastructure/primary/HomeRouter.spec.ts"))
.and()
.apply(patchTsConfig(properties))
.apply(patchVitestConfig(properties))
.build();
//@formatter:on
}
Expand All @@ -120,6 +120,26 @@ private static String compilerOption(String optionName, boolean optionValue, Ind
return indentation.times(2) + "\"%s\": %s,".formatted(optionName, optionValue);
}

private Consumer<JHipsterModuleBuilder> patchVitestConfig(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder -> moduleBuilder
.mandatoryReplacements()
.in(path("vitest.config.ts"))
.add(lineAfterRegex("from 'vitest/config';"), "import vue from '@vitejs/plugin-vue';")
.add(new TextReplacer(notContainingReplacement(), "plugins: ["), "plugins: [vue(), ")
.add(text("environment: 'node',"), "environment: 'jsdom',")
.add(lineAfterRegex("configDefaults.coverage.exclude"), vitestCoverageExclusion(properties.indentation(),"src/main/webapp/**/*.component.ts"))
.add(lineAfterRegex("configDefaults.coverage.exclude"), vitestCoverageExclusion(properties.indentation(),"src/main/webapp/app/router.ts"))
.add(lineAfterRegex("configDefaults.coverage.exclude"), vitestCoverageExclusion(properties.indentation(),"src/main/webapp/app/injections.ts"))
.add(lineAfterRegex("configDefaults.coverage.exclude"), vitestCoverageExclusion(properties.indentation(),"src/main/webapp/app/main.ts"))
.and();
//@formatter:on
}

private static String vitestCoverageExclusion(Indentation indentation, String filePattern) {
return indentation.times(4) + "'" + filePattern + "',";
}

public JHipsterModule buildPiniaModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

Expand Down
50 changes: 0 additions & 50 deletions src/main/resources/generator/client/vue/vitest.config.ts.mustache

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default defineConfig({
cache: false,
include: ['src/test/webapp/unit/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
coverage: {
all: true,
thresholds: {
perFile: true,
autoUpdate: true,
Expand All @@ -32,7 +31,6 @@ export default defineConfig({
exclude: [
...configDefaults.coverage.exclude as string[],
],
clean: true,
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 @@ -24,7 +24,7 @@ void shouldCreateVueModule() {
JHipsterModule module = factory.buildVueModule(properties);

//@formatter:off
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile(), tsConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile(), tsConfigFile(), vitestConfigFile())
.hasFiles("documentation/vue.md")
.hasFile("package.json")
.notContaining(nodeDependency("@tsconfig/recommended"))
Expand Down Expand Up @@ -62,11 +62,25 @@ void shouldCreateVueModule() {
.and()
.hasPrefixedFiles("", "eslint.config.js", "tsconfig.build.json", "vite.config.ts", "vitest.config.ts")
.hasFile("tsconfig.json")
.containing("\"extends\": \"@vue/tsconfig/tsconfig.dom.json\"")
.containing("\"allowJs\": true,")
.containing("\"sourceMap\": true,")
.containing("\"types\": [\"vite/client\", ")
.and()
.containing("\"extends\": \"@vue/tsconfig/tsconfig.dom.json\"")
.containing("\"allowJs\": true,")
.containing("\"sourceMap\": true,")
.containing("\"types\": [\"vite/client\", ")
.and()
.hasFile("vitest.config.ts")
.containing("import vue from '@vitejs/plugin-vue';")
.containing("plugins: [vue(), tsconfigPaths()],")
.containing("environment: 'jsdom',")
.containing("""
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',
"""
)
.and()
.hasFiles("src/main/webapp/app/shared/http/infrastructure/secondary/AxiosHttp.ts")
.hasFiles("src/main/webapp/index.html")
.hasPrefixedFiles("src/main/webapp/app", "env.d.ts", "AppVue.vue", "injections.ts", "router.ts", "main.ts")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.jhipster.lite.module.infrastructure.secondary;

import static org.assertj.core.api.Assertions.*;
import static tech.jhipster.lite.TestFileUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
import static tech.jhipster.lite.TestFileUtils.contentNormalizingNewLines;

import java.io.IOException;
import java.nio.file.*;
Expand Down Expand Up @@ -64,6 +64,10 @@ public static ModuleFile tsConfigFile() {
return file("src/main/resources/generator/typescript/tsconfig.json", "tsconfig.json");
}

public static ModuleFile vitestConfigFile() {
return file("src/main/resources/generator/typescript/vitest.config.ts.mustache", "vitest.config.ts");
}

public static ModuleFile emptyLintStagedConfigFile() {
return file("src/test/resources/projects/init/.lintstagedrc.empty.cjs", ".lintstagedrc.cjs");
}
Expand Down

0 comments on commit bc8e287

Please sign in to comment.