Skip to content

Commit

Permalink
fix: import cache (#259)
Browse files Browse the repository at this point in the history
* fix: import cache

* chore: add test for import cache & config search error

* chore: update describe name

* chore: search ghost dir

* chore: remove .href of pathToFileURL

---------

Co-authored-by: pengbo43 <pengbo43@jd.com>
  • Loading branch information
PengBoUESTC and pengbo43 committed Feb 8, 2024
1 parent 2c42a73 commit 3ade20e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/req.js
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
@@ -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
@@ -0,0 +1 @@
export default {"map":false}
9 changes: 9 additions & 0 deletions test/rc.test.js
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)
})
})
})

0 comments on commit 3ade20e

Please sign in to comment.