blob: 8c262bd228d623cc78549d521d4fdad8295ada9b [file]
import assert from 'node:assert/strict';
import { describe, test } from 'node:test';
import { bareCssImportSpecifiers } from './third-party-closure.mjs';
// The bundle recorder cannot see a package reached only through a CSS
// `@import` of pure rules — Vite inlines it at transform time, so it never
// becomes a module, and with no `url()` asset it emits nothing either. The
// notice generator therefore reads the stylesheets, and this is the reader.
describe('bareCssImportSpecifiers', () => {
test('finds package names behind every @import spelling', () => {
const css = `
@import "normalize.css";
@import 'modern-css-reset';
@import url("some-pkg/theme.css");
@import "@scope/pkg/dist/base.css" layer(components);
@import "@scope/only-root";
@import "tokens.css" screen and (min-width: 40em);
@import url(unquoted-pkg/base.css);
@import url( spaced-pkg );
`;
assert.deepEqual(bareCssImportSpecifiers(css).sort(), [
'@scope/only-root',
'@scope/pkg',
'modern-css-reset',
'normalize.css',
'some-pkg',
'spaced-pkg',
'tokens.css',
'unquoted-pkg',
]);
});
test('ignores anything that is not a package name', () => {
const css = `
@import "./cascade-layers.css";
@import "../shared/base.css";
@import "/absolute.css";
@import url("https://fonts.example/font.css");
@import url("data:text/css,body{}");
`;
assert.deepEqual(bareCssImportSpecifiers(css), []);
});
test('reports a scoped package once however deeply it is imported', () => {
const css = `
@import "@astryxdesign/core/reset.css";
@import "@astryxdesign/core/astryx.css" layer(astryx-components);
`;
assert.deepEqual(bareCssImportSpecifiers(css), ['@astryxdesign/core']);
});
});