diff --git a/test/config.js b/test/config.js index a4eb8c6..d75449c 100644 --- a/test/config.js +++ b/test/config.js @@ -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 = {}` diff --git a/test/helpers/env.js b/test/helpers/env.js index 7ec542e..dfdba26 100644 --- a/test/helpers/env.js +++ b/test/helpers/env.js @@ -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([ @@ -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) }