Skip to content

Commit

Permalink
add integration tests for tailwind.config.ts and `tailwind.config.j…
Browse files Browse the repository at this point in the history
…s` with ESM syntax
  • Loading branch information
RobinMalfait committed Mar 29, 2023
1 parent b6798de commit 4240fc3
Show file tree
Hide file tree
Showing 6 changed files with 699 additions and 12 deletions.
133 changes: 130 additions & 3 deletions integrations/parcel/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ let { css, html, javascript } = require('../../syntax')
let { env } = require('../../../lib/lib/sharedState')

let {
readOutputFile,
appendToInputFile,
writeInputFile,
waitForOutputFileCreation,
readOutputFile,
removeFile,
waitForOutputFileChange,
waitForOutputFileCreation,
writeInputFile,
} = require('../../io')({ output: 'dist', input: 'src' })

describe('static build', () => {
Expand All @@ -32,6 +33,132 @@ describe('static build', () => {
`
)
})

it('can use a tailwind.config.js configuration file with ESM syntax', async () => {
await removeFile('tailwind.config.js')
await writeInputFile(
'index.html',
html`
<link rel="stylesheet" href="./index.css" />
<div class="bg-primary"></div>
`
)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await writeInputFile(
'../tailwind.config.js',
javascript`
export default {
content: ['./src/index.html'],
theme: {
extend: {
colors: {
primary: 'black',
},
},
},
corePlugins: {
preflight: false,
},
}
`
)

await $('parcel build ./src/index.html --no-cache', {
env: { NODE_ENV: 'production' },
})

if (!env.OXIDE) {
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.bg-primary {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
`
)
}

if (env.OXIDE) {
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.bg-primary {
background-color: black;
}
`
)
}
})

it('can use a tailwind.config.ts configuration file', async () => {
await removeFile('tailwind.config.js')
await writeInputFile(
'index.html',
html`
<link rel="stylesheet" href="./index.css" />
<div class="bg-primary"></div>
`
)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await writeInputFile(
'../tailwind.config.ts',
javascript`
import type { Config } from 'tailwindcss'
export default {
content: ['./src/index.html'],
theme: {
extend: {
colors: {
primary: 'black',
},
},
},
corePlugins: {
preflight: false,
},
} satisfies Config
`
)

await $('parcel build ./src/index.html --no-cache', {
env: { NODE_ENV: 'production' },
})

if (!env.OXIDE) {
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.bg-primary {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
`
)
}

if (env.OXIDE) {
expect(await readOutputFile(/index\.\w+\.css$/)).toIncludeCss(
css`
.bg-primary {
background-color: black;
}
`
)
}
})
})

describe('watcher', () => {
Expand Down
116 changes: 115 additions & 1 deletion integrations/rollup/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let $ = require('../../execute')
let { css, html, javascript } = require('../../syntax')
let { env } = require('../../../lib/lib/sharedState')

let { readOutputFile, appendToInputFile, writeInputFile } = require('../../io')({
let { readOutputFile, appendToInputFile, writeInputFile, removeFile } = require('../../io')({
output: 'dist',
input: 'src',
})
Expand All @@ -27,6 +27,120 @@ describe('static build', () => {
`
)
})

it('can use a tailwind.config.js configuration file with ESM syntax', async () => {
await removeFile('tailwind.config.js')
await writeInputFile('index.html', html`<div class="bg-primary"></div>`)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await writeInputFile(
'../tailwind.config.js',
javascript`
export default {
content: ['./src/index.html'],
theme: {
extend: {
colors: {
primary: 'black',
},
},
},
corePlugins: {
preflight: false,
},
}
`
)

await $('rollup -c', {
env: { NODE_ENV: 'production' },
})

if (!env.OXIDE) {
expect(await readOutputFile('index.css')).toIncludeCss(
css`
.bg-primary {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
`
)
}

if (env.OXIDE) {
expect(await readOutputFile('index.css')).toIncludeCss(
css`
.bg-primary {
background-color: black;
}
`
)
}
})

it('can use a tailwind.config.ts configuration file', async () => {
await removeFile('tailwind.config.js')
await writeInputFile('index.html', html`<div class="bg-primary"></div>`)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await writeInputFile(
'../tailwind.config.ts',
javascript`
import type { Config } from 'tailwindcss'
export default {
content: ['./src/index.html'],
theme: {
extend: {
colors: {
primary: 'black',
},
},
},
corePlugins: {
preflight: false,
},
} satisfies Config
`
)

await $('rollup -c', {
env: { NODE_ENV: 'production' },
})

if (!env.OXIDE) {
expect(await readOutputFile('index.css')).toIncludeCss(
css`
.bg-primary {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
`
)
}

if (env.OXIDE) {
expect(await readOutputFile('index.css')).toIncludeCss(
css`
.bg-primary {
background-color: black;
}
`
)
}
})
})

describe('watcher', () => {
Expand Down
Loading

0 comments on commit 4240fc3

Please sign in to comment.