Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import cache #259

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/req.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function req(name, rootFile = __filename) {
let url = createRequire(rootFile).resolve(name)

try {
return (await import(pathToFileURL(url).href)).default
return (await import(`${pathToFileURL(url)}?t=${Date.now()}`)).default
} catch (err) {
if (!TS_EXT_RE.test(url)) {
/* c8 ignore start */
Expand Down
20 changes: 20 additions & 0 deletions test/import.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { describe, test } = require('node:test')
const { equal } = require('node:assert')
const { writeFileSync } = require('node:fs')
const postcssrc = require('../src/index.js')

describe('.postcss.config.js Load Config', () => {
test('.postcss.config.js config update cache', () => {

return postcssrc({}, 'test').then(config => {
let { file, options } = config
equal(options.map, false)
writeFileSync(file, `export default ${JSON.stringify({ map: true })}`)
postcssrc({}, 'test').then(({ options: newOptions }) => {
equal(newOptions.map, true)
}).finally(() => {
writeFileSync(file, `export default ${JSON.stringify({ map: false })}`)
})
})
})
})
1 change: 1 addition & 0 deletions test/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {"map":false}
9 changes: 9 additions & 0 deletions test/rc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ test('.postcssrc - {Object} - Process SSS', () => {
})
})
})

describe('Load Config Error', () => {
test('no config found error', () => {
return postcssrc({}, 'ghostDir')
.catch(error => {
equal(error.message.startsWith("No PostCSS Config found in:"), true)
})
})
})