Skip to content

Commit

Permalink
Add tests for ESM config
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Jun 30, 2022
1 parent a1e547e commit d779476
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 25 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ test('supports common config', async (t) => {
)
})

test('supports ESM config', async (t) => {
const env = `import postcssImport from 'postcss-import'
export default function () {
return {
plugins: [
postcssImport()
]
}
}`

const dir = await ENV(env, ['a.css'], 'mjs')

const { error, stderr } = await cli(
['a.css', '-o', 'output.css', '--no-map'],
dir
)

t.falsy(error, stderr)

t.is(
await read(path.join(dir, 'output.css')),
await read('test/fixtures/a.css')
)
})

test("doesn't error on empty config", async (t) => {
const env = `module.exports = {}`

Expand Down
5 changes: 2 additions & 3 deletions test/helpers/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { globby } from 'globby'

import tmp from './tmp.js'

export default function (config, fixtures) {
fixtures = fixtures || '**/*'
export default function (config, fixtures = '**/*', extension = 'cjs') {
const dir = tmp()

return Promise.all([
Expand All @@ -14,6 +13,6 @@ export default function (config, fixtures) {
return fs.copy(path.join('test/fixtures', item), path.join(dir, item))
})
}),
fs.outputFile(path.join(dir, 'postcss.config.cjs'), config),
fs.outputFile(path.join(dir, `postcss.config.${extension}`), config),
]).then(() => dir)
}

0 comments on commit d779476

Please sign in to comment.