Skip to content

Commit

Permalink
test(generator): allow reusing lintstaged config file from custom jhl…
Browse files Browse the repository at this point in the history
…ite modules
  • Loading branch information
murdos committed Feb 5, 2025
1 parent 3823b76 commit 8af39f8
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.mockito.Mockito.verify;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFileWithPrettier;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeDependency;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeScript;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.packageJsonFile;
Expand Down Expand Up @@ -37,7 +37,7 @@ void shouldCreateAngularModule() {

JHipsterModule module = factory.buildModule(properties);

assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFileWithPrettier())
.hasFile("package.json")
.containing(nodeDependency("zone.js"))
.containing(nodeDependency("tslib"))
Expand Down Expand Up @@ -130,7 +130,7 @@ void shouldProxyBeUpdatedWhenServerPortPropertyNotDefault() {
.build();

JHipsterModule module = factory.buildModule(properties);
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFileWithPrettier())
.hasFile("proxy.conf.json")
.containing("\"target\": \"http://localhost:8081\"")
.notContaining("\"target\": \"http://localhost:8080\"");
Expand All @@ -143,7 +143,7 @@ void shouldProxyBeDefaultWhenServerPortPropertyMissing() {
.build();

JHipsterModule module = factory.buildModule(properties);
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFileWithPrettier())
.hasFile("proxy.conf.json")
.containing("\"target\": \"http://localhost:8080\"");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.mockito.Mockito.verify;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.eslintConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFileWithPrettier;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeDependency;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.packageJsonFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.tsConfigFile;
Expand Down Expand Up @@ -38,7 +38,14 @@ void shouldBuildModuleWithStyle() {
.build();
JHipsterModule module = factory.buildModule(properties);

assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile(), eslintConfigFile(), tsConfigFile(), vitestConfigFile())
assertThatModuleWithFiles(
module,
packageJsonFile(),
lintStagedConfigFileWithPrettier(),
eslintConfigFile(),
tsConfigFile(),
vitestConfigFile()
)
.hasFile("package.json")
.notContaining(nodeDependency("@tsconfig/recommended"))
.containing(nodeDependency("@testing-library/dom"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.mockito.Mockito.verify;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFileWithPrettier;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeDependency;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeScript;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.packageJsonFile;
Expand Down Expand Up @@ -36,7 +36,7 @@ void shouldCreateSvelteModule() {
JHipsterModule module = factory.buildSvelteModule(properties);

// @formatter:off
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFileWithPrettier())
.hasFile(".gitignore")
.containing("""
# Svelte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.ModuleFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.eslintConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFileWithPrettier;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeDependency;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeScript;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.packageJsonFile;
Expand Down Expand Up @@ -43,7 +43,7 @@ void shouldCreateVueModule() {
JHipsterModule module = factory.buildVueModule(properties);

//@formatter:off
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile(), tsConfigFile(), vitestConfigFile(), eslintConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFileWithPrettier(), tsConfigFile(), vitestConfigFile(), eslintConfigFile())
.hasFiles("documentation/vue.md")
.hasFile("package.json")
.notContaining(nodeDependency("@tsconfig/recommended"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package tech.jhipster.lite.generator.prettier.domain;

import static org.mockito.Mockito.verify;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.emptyLintStagedConfigFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.lintStagedConfigFileWithoutPrettier;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeDependency;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.nodeScript;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.packageJsonFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -19,6 +14,7 @@
import tech.jhipster.lite.module.domain.JHipsterModulesFixture;
import tech.jhipster.lite.module.domain.npm.NpmLazyInstaller;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions;

@UnitTest
@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -78,7 +74,7 @@ void shouldBuildModuleWithEmptyLintStaged() {

JHipsterModule module = factory.buildModule(properties);

assertThatModuleWithFiles(module, packageJsonFile(), emptyLintStagedConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
.hasFile(".lintstagedrc.cjs")
.containing(
"""
Expand All @@ -97,4 +93,8 @@ private JHipsterModuleProperties properties(String folder) {
.put("endOfLine", "crlf")
.build();
}

public static JHipsterModulesAssertions.ModuleFile lintStagedConfigFileWithoutPrettier() {
return file("src/test/resources/projects/init/.lintstagedrc.withoutPrettier.cjs", ".lintstagedrc.cjs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void shouldBuildModuleForMaven() {

JHipsterModule module = factory.buildProtobufBackwardsCompatibilityCheckModule(properties);

assertThatModuleWithFiles(module, pomFile(), lintStagedConfigFile())
assertThatModuleWithFiles(module, pomFile(), lintStagedConfigFileWithPrettier())
.hasFile(".lintstagedrc.cjs")
.containing(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public static ModuleFile packageJsonFile() {
}

public static ModuleFile lintStagedConfigFile() {
return file("src/test/resources/projects/init/.lintstagedrc.cjs", ".lintstagedrc.cjs");
return fileFromClasspath("generator/init/.lintstagedrc.cjs", ".lintstagedrc.cjs");
}

public static ModuleFile lintStagedConfigFileWithPrettier() {
return fileFromClasspath("projects/init/.lintstagedrc.withPrettierModuleApplied.cjs", ".lintstagedrc.cjs");
}

public static ModuleFile tsConfigFile() {
Expand All @@ -82,14 +86,6 @@ public static ModuleFile eslintConfigFile() {
return fileFromClasspath("generator/typescript/eslint.config.js.mustache", "eslint.config.js");
}

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

public static ModuleFile lintStagedConfigFileWithoutPrettier() {
return file("src/test/resources/projects/init/.lintstagedrc.withoutPrettier.cjs", ".lintstagedrc.cjs");
}

public static ModuleFile readmeFile() {
return fileFromClasspath("generator/init/README.md.mustache", "README.md");
}
Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/projects/init/.lintstagedrc.empty.cjs

This file was deleted.

0 comments on commit 8af39f8

Please sign in to comment.