Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace authored and RobinMalfait committed Jan 28, 2025
1 parent b7d5e4c commit c22a381
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
77 changes: 77 additions & 0 deletions integrations/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,83 @@ describe.each([
])
},
)

test(
'git ignore files outside of a repo are not considered',
{
fs: {
// Ignore everything in the "home" directory
'home/.gitignore': '*',

// Only ignore files called ignore-*.html in the actual git repo
'home/project/.gitignore': 'ignore-*.html',

'home/project/package.json': json`
{
"type": "module",
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,

'home/project/src/index.css': css` @import 'tailwindcss'; `,
'home/project/src/index.html': html`
<div
class="content-['index.html']"
></div>
`,
'home/project/src/ignore-1.html': html`
<div
class="content-['ignore-1.html']"
></div>
`,
'home/project/src/ignore-2.html': html`
<div
class="content-['ignore-2.html']"
></div>
`,
},

installDependencies: false,
},
async ({ fs, root, exec }) => {
await exec(`pnpm install --ignore-workspace`, {
cwd: path.join(root, 'home/project'),
})

// No git repo = all ignore files are considered
await exec(`${command} --input src/index.css --output dist/out.css`, {
cwd: path.join(root, 'home/project'),
})

await fs.expectFileNotToContain('./home/project/dist/out.css', [
candidate`content-['index.html']`,
candidate`content-['ignore-1.html']`,
candidate`content-['ignore-2.html']`,
])

// Make home/project a git repo
// Only ignore files within the repo are considered
await exec(`git init`, {
cwd: path.join(root, 'home/project'),
})

await exec(`${command} --input src/index.css --output dist/out.css`, {
cwd: path.join(root, 'home/project'),
})

await fs.expectFileToContain('./home/project/dist/out.css', [
candidate`content-['index.html']`,
])

await fs.expectFileNotToContain('./home/project/dist/out.css', [
candidate`content-['ignore-1.html']`,
candidate`content-['ignore-2.html']`,
])
},
)
})

test(
Expand Down
10 changes: 8 additions & 2 deletions integrations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ interface TestConfig {
fs: {
[filePath: string]: string | Uint8Array
}

installDependencies?: boolean
}
interface TestContext {
root: string
Expand Down Expand Up @@ -382,14 +384,18 @@ export function test(
await context.fs.write(filename, content)
}

let shouldInstallDependencies = config.installDependencies ?? true

try {
// In debug mode, the directory is going to be inside the pnpm workspace
// of the tailwindcss package. This means that `pnpm install` will run
// pnpm install on the workspace instead (expect if the root dir defines
// a separate workspace). We work around this by using the
// `--ignore-workspace` flag.
let ignoreWorkspace = debug && !config.fs['pnpm-workspace.yaml']
await context.exec(`pnpm install${ignoreWorkspace ? ' --ignore-workspace' : ''}`)
if (shouldInstallDependencies) {
let ignoreWorkspace = debug && !config.fs['pnpm-workspace.yaml']
await context.exec(`pnpm install${ignoreWorkspace ? ' --ignore-workspace' : ''}`)
}
} catch (error: any) {
console.error(error)
console.error(error.stdout?.toString())
Expand Down

0 comments on commit c22a381

Please sign in to comment.