@@ -3,6 +3,43 @@ import { afterEach, beforeEach, describe, expect, test } from "vitest";
33import { getCurrentPackageManager } from "./utils/package-manager" ;
44import { TestEnvironment } from "./utils/test-environment" ;
55
6+ const expectGeneratedConfigToBeFormatted = async ( {
7+ env,
8+ appPath,
9+ expectedGeneratedFiles,
10+ } : {
11+ env : TestEnvironment ;
12+ appPath : string ;
13+ expectedGeneratedFiles : string [ ] ;
14+ } ) => {
15+ const generatedFilesThatExist = expectedGeneratedFiles . filter ( ( filePath ) =>
16+ env . fileExists ( appPath , filePath ) ,
17+ ) ;
18+ const prettierCheckResult = await env . runPrettierCheckIfInstalled (
19+ appPath ,
20+ generatedFilesThatExist ,
21+ ) ;
22+ expect ( prettierCheckResult . success , prettierCheckResult . output ) . toBe ( true ) ;
23+ } ;
24+
25+ const expectCommitlintHookToAllowMessage = async ( {
26+ env,
27+ appPath,
28+ message,
29+ } : {
30+ env : TestEnvironment ;
31+ appPath : string ;
32+ message : string ;
33+ } ) => {
34+ env . writeFile (
35+ appPath ,
36+ "commitlint-hook-test.txt" ,
37+ `commitlint hook test ${ Date . now ( ) } \n` ,
38+ ) ;
39+ const commitResult = await env . commitWithMessage ( appPath , message ) ;
40+ expect ( commitResult . success , commitResult . output ) . toBe ( true ) ;
41+ } ;
42+
643describe ( "Next.js Integration Tests" , ( ) => {
744 let testEnv : TestEnvironment ;
845 const packageManager = getCurrentPackageManager ( ) ;
@@ -27,6 +64,18 @@ describe("Next.js Integration Tests", () => {
2764 const output = await env . runSolvroConfig ( appPath , [ "--all" , "--force" ] ) ;
2865 expect ( output ) . toContain ( "Konfiguracja zakończona pomyślnie" ) ;
2966
67+ await expectGeneratedConfigToBeFormatted ( {
68+ env,
69+ appPath,
70+ expectedGeneratedFiles : [
71+ "eslint.config.js" ,
72+ "package.json" ,
73+ ".github/workflows/ci.yml" ,
74+ ".github/dependabot.yml" ,
75+ ".commitlintrc.js" ,
76+ ] ,
77+ } ) ;
78+
3079 const prettierResult = await env . runPrettier ( appPath , true ) ;
3180 expect ( prettierResult . success ) . toBe ( true ) ;
3281
@@ -77,6 +126,18 @@ describe("NestJS Integration Tests", () => {
77126 const output = await env . runSolvroConfig ( appPath , [ "--all" , "--force" ] ) ;
78127 expect ( output ) . toContain ( "Konfiguracja zakończona pomyślnie" ) ;
79128
129+ await expectGeneratedConfigToBeFormatted ( {
130+ env,
131+ appPath,
132+ expectedGeneratedFiles : [
133+ "eslint.config.mjs" ,
134+ "package.json" ,
135+ ".github/workflows/ci.yml" ,
136+ ".github/dependabot.yml" ,
137+ ".commitlintrc.js" ,
138+ ] ,
139+ } ) ;
140+
80141 const prettierResult = await env . runPrettier ( appPath , true ) ;
81142 expect ( prettierResult . success ) . toBe ( true ) ;
82143
@@ -127,6 +188,18 @@ describe("Vite Integration Tests", () => {
127188 const output = await env . runSolvroConfig ( appPath , [ "--all" , "--force" ] ) ;
128189 expect ( output ) . toContain ( "Konfiguracja zakończona pomyślnie" ) ;
129190
191+ await expectGeneratedConfigToBeFormatted ( {
192+ env,
193+ appPath,
194+ expectedGeneratedFiles : [
195+ "eslint.config.js" ,
196+ "package.json" ,
197+ ".github/workflows/ci.yml" ,
198+ ".github/dependabot.yml" ,
199+ ".commitlintrc.js" ,
200+ ] ,
201+ } ) ;
202+
130203 const prettierResult = await env . runPrettier ( appPath , true ) ;
131204 expect ( prettierResult . success ) . toBe ( true ) ;
132205
@@ -154,3 +227,55 @@ describe("Vite Integration Tests", () => {
154227 expect ( packageJson ) . toContain ( '"prettier": "@solvro/config/prettier"' ) ;
155228 } ) ;
156229} ) ;
230+
231+ describe ( "Commitlint Integration Tests" , ( ) => {
232+ let testEnv : TestEnvironment ;
233+ const packageManager = getCurrentPackageManager ( ) ;
234+
235+ beforeEach ( async ( ) => {
236+ testEnv = new TestEnvironment ( "commitlint-integration" , packageManager ) ;
237+ } ) ;
238+
239+ afterEach ( ( ) => {
240+ testEnv ?. cleanup ( ) ;
241+ } ) ;
242+
243+ test ( `should allow valid commit message through husky commit-msg hook with ${ packageManager . name } ` , async ( ) => {
244+ const env = testEnv ;
245+ await env . setup ( ) ;
246+
247+ const appPath = await env . createNextjsApp ( "commitlint-test-app" ) ;
248+ await env . installSolvroConfig ( appPath ) ;
249+ await env . initGitRepo ( appPath ) ;
250+
251+ const output = await env . runSolvroConfig ( appPath , [
252+ "--commitlint" ,
253+ "--force" ,
254+ ] ) ;
255+ expect ( output ) . toContain ( "Konfiguracja zakończona pomyślnie" ) ;
256+
257+ await expectGeneratedConfigToBeFormatted ( {
258+ env,
259+ appPath,
260+ expectedGeneratedFiles : [ "package.json" , ".commitlintrc.js" ] ,
261+ } ) ;
262+
263+ const packageJson = JSON . parse ( env . readFile ( appPath , "package.json" ) ) as {
264+ scripts ?: Record < string , string > ;
265+ } ;
266+ packageJson . scripts = packageJson . scripts ?? { } ;
267+ packageJson . scripts . test = packageJson . scripts . test ?? "true" ;
268+ ( packageJson as { type ?: string } ) . type = "module" ;
269+ env . writeFile (
270+ appPath ,
271+ "package.json" ,
272+ JSON . stringify ( packageJson , null , 2 ) ,
273+ ) ;
274+
275+ await expectCommitlintHookToAllowMessage ( {
276+ env,
277+ appPath,
278+ message : "chore: test commit" ,
279+ } ) ;
280+ } ) ;
281+ } ) ;
0 commit comments