Skip to content

Commit c22a381

Browse files
thecrypticaceRobinMalfait
authored andcommitted
Add integration test
1 parent b7d5e4c commit c22a381

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

integrations/cli/index.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,83 @@ describe.each([
556556
])
557557
},
558558
)
559+
560+
test(
561+
'git ignore files outside of a repo are not considered',
562+
{
563+
fs: {
564+
// Ignore everything in the "home" directory
565+
'home/.gitignore': '*',
566+
567+
// Only ignore files called ignore-*.html in the actual git repo
568+
'home/project/.gitignore': 'ignore-*.html',
569+
570+
'home/project/package.json': json`
571+
{
572+
"type": "module",
573+
"dependencies": {
574+
"tailwindcss": "workspace:^",
575+
"@tailwindcss/cli": "workspace:^"
576+
}
577+
}
578+
`,
579+
580+
'home/project/src/index.css': css` @import 'tailwindcss'; `,
581+
'home/project/src/index.html': html`
582+
<div
583+
class="content-['index.html']"
584+
></div>
585+
`,
586+
'home/project/src/ignore-1.html': html`
587+
<div
588+
class="content-['ignore-1.html']"
589+
></div>
590+
`,
591+
'home/project/src/ignore-2.html': html`
592+
<div
593+
class="content-['ignore-2.html']"
594+
></div>
595+
`,
596+
},
597+
598+
installDependencies: false,
599+
},
600+
async ({ fs, root, exec }) => {
601+
await exec(`pnpm install --ignore-workspace`, {
602+
cwd: path.join(root, 'home/project'),
603+
})
604+
605+
// No git repo = all ignore files are considered
606+
await exec(`${command} --input src/index.css --output dist/out.css`, {
607+
cwd: path.join(root, 'home/project'),
608+
})
609+
610+
await fs.expectFileNotToContain('./home/project/dist/out.css', [
611+
candidate`content-['index.html']`,
612+
candidate`content-['ignore-1.html']`,
613+
candidate`content-['ignore-2.html']`,
614+
])
615+
616+
// Make home/project a git repo
617+
// Only ignore files within the repo are considered
618+
await exec(`git init`, {
619+
cwd: path.join(root, 'home/project'),
620+
})
621+
622+
await exec(`${command} --input src/index.css --output dist/out.css`, {
623+
cwd: path.join(root, 'home/project'),
624+
})
625+
626+
await fs.expectFileToContain('./home/project/dist/out.css', [
627+
candidate`content-['index.html']`,
628+
])
629+
630+
await fs.expectFileNotToContain('./home/project/dist/out.css', [
631+
candidate`content-['ignore-1.html']`,
632+
candidate`content-['ignore-2.html']`,
633+
])
634+
},
635+
)
559636
})
560637

561638
test(

integrations/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ interface TestConfig {
3232
fs: {
3333
[filePath: string]: string | Uint8Array
3434
}
35+
36+
installDependencies?: boolean
3537
}
3638
interface TestContext {
3739
root: string
@@ -382,14 +384,18 @@ export function test(
382384
await context.fs.write(filename, content)
383385
}
384386

387+
let shouldInstallDependencies = config.installDependencies ?? true
388+
385389
try {
386390
// In debug mode, the directory is going to be inside the pnpm workspace
387391
// of the tailwindcss package. This means that `pnpm install` will run
388392
// pnpm install on the workspace instead (expect if the root dir defines
389393
// a separate workspace). We work around this by using the
390394
// `--ignore-workspace` flag.
391-
let ignoreWorkspace = debug && !config.fs['pnpm-workspace.yaml']
392-
await context.exec(`pnpm install${ignoreWorkspace ? ' --ignore-workspace' : ''}`)
395+
if (shouldInstallDependencies) {
396+
let ignoreWorkspace = debug && !config.fs['pnpm-workspace.yaml']
397+
await context.exec(`pnpm install${ignoreWorkspace ? ' --ignore-workspace' : ''}`)
398+
}
393399
} catch (error: any) {
394400
console.error(error)
395401
console.error(error.stdout?.toString())

0 commit comments

Comments
 (0)