Skip to content

Commit d779476

Browse files
committed
Add tests for ESM config
1 parent a1e547e commit d779476

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

test/config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ test('supports common config', async (t) => {
2828
)
2929
})
3030

31+
test('supports ESM config', async (t) => {
32+
const env = `import postcssImport from 'postcss-import'
33+
export default function () {
34+
return {
35+
plugins: [
36+
postcssImport()
37+
]
38+
}
39+
}`
40+
41+
const dir = await ENV(env, ['a.css'], 'mjs')
42+
43+
const { error, stderr } = await cli(
44+
['a.css', '-o', 'output.css', '--no-map'],
45+
dir
46+
)
47+
48+
t.falsy(error, stderr)
49+
50+
t.is(
51+
await read(path.join(dir, 'output.css')),
52+
await read('test/fixtures/a.css')
53+
)
54+
})
55+
3156
test("doesn't error on empty config", async (t) => {
3257
const env = `module.exports = {}`
3358

test/helpers/env.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { globby } from 'globby'
44

55
import tmp from './tmp.js'
66

7-
export default function (config, fixtures) {
8-
fixtures = fixtures || '**/*'
7+
export default function (config, fixtures = '**/*', extension = 'cjs') {
98
const dir = tmp()
109

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

0 commit comments

Comments
 (0)