-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make PostCSS dependency messages more consistent
- Loading branch information
1 parent
3dbff7f
commit fbb0cf3
Showing
7 changed files
with
123 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import plugin from '@csstools/postcss-sass'; | ||
import postcss from 'postcss'; | ||
import test from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
|
||
test('emits dependency messages', async () => { | ||
const source = '@import "components/colors";'; | ||
|
||
const result = await postcss([plugin]).process(source, { | ||
from: 'test/basic.scss', | ||
}); | ||
|
||
assert.deepStrictEqual(result.warnings(), []); | ||
assert.deepStrictEqual( | ||
result.messages.map((x) => { | ||
x.file = x.file.split('test')[1]; | ||
x.parent = x.parent.split('test')[1]; | ||
|
||
return x; | ||
}), | ||
[ | ||
{ | ||
type: 'dependency', | ||
plugin: 'postcss-sass', | ||
file: '/components/colors.scss', | ||
parent: '/basic.scss', | ||
}, | ||
], | ||
); | ||
}); | ||
|
||
test('emits dependency messages with custom importer', async () => { | ||
const source = ` | ||
@import "custom:colors"; | ||
@import "components/fonts"; | ||
@import "components/page"; | ||
`; | ||
|
||
const result = await postcss([plugin({ | ||
importer: (id, parentId, done) => { | ||
if (id === 'custom:colors') { | ||
done({ file: 'test/components/colors.scss', contents: '$primary-color: #333;' }); | ||
} | ||
}, | ||
})]).process(source, { | ||
from: 'test/basic.scss', | ||
}); | ||
|
||
assert.deepStrictEqual(result.warnings(), []); | ||
assert.deepStrictEqual( | ||
result.messages.map((x) => { | ||
x.file = x.file.split('test')[1]; | ||
x.parent = x.parent.split('test')[1]; | ||
|
||
return x; | ||
}), | ||
[ | ||
{ | ||
type: 'dependency', | ||
plugin: 'postcss-sass', | ||
file: '/components/colors.scss', | ||
parent: '/basic.scss', | ||
}, | ||
{ | ||
type: 'dependency', | ||
plugin: 'postcss-sass', | ||
file: '/components/colors.scss', | ||
parent: '/basic.scss', | ||
}, | ||
{ | ||
type: 'dependency', | ||
plugin: 'postcss-sass', | ||
file: '/components/fonts.scss', | ||
parent: '/basic.scss', | ||
}, | ||
{ | ||
type: 'dependency', | ||
plugin: 'postcss-sass', | ||
file: '/components/page.scss', | ||
parent: '/basic.scss', | ||
}], | ||
); | ||
}); |