Skip to content

Commit 2f23476

Browse files
authored
test: import attrs (#72)
* chore: package lock * test: import attrs * test: import attrs
1 parent 8c69d07 commit 2f23476

File tree

9 files changed

+89
-18
lines changed

9 files changed

+89
-18
lines changed

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Tests CSS import attributes with inline: false
2+
// Unlike import-attrs (which uses inline: true), this generates a separate .css.js file
3+
// instead of inlining the CSS content directly into the JavaScript output
4+
import { LitElement } from 'lit';
5+
import styles from "./styles.css.js";
6+
export class MyEl extends LitElement {
7+
static styles = [styles];
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { LitElement } from 'lit';
2+
import { css } from "lit";
3+
const styles = css `:host {
4+
display: block;
5+
color: red;
6+
}
7+
`;
8+
export class MyEl extends LitElement {
9+
static styles = [styles];
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Tests CSS import attributes with inline: false
2+
// Unlike import-attrs (which uses inline: true), this generates a separate .css.js file
3+
// instead of inlining the CSS content directly into the JavaScript output
4+
import { LitElement } from 'lit';
5+
6+
import styles from './styles.css' with { type: 'css' };
7+
8+
export class MyEl extends LitElement {
9+
static readonly styles = [styles];
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:host {
2+
display: block;
3+
color: blue;
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"include": [".", "../declaration.d.ts"],
3+
"compilerOptions": {
4+
"outDir": "../../TSPC_OUTPUT/import-attrs-module",
5+
"module": "NodeNext",
6+
"plugins": [
7+
{
8+
"transform": "typescript-transform-lit-css",
9+
"inline": false,
10+
"cssnano": false
11+
}
12+
]
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { LitElement } from 'lit';
2+
3+
import styles from './styles.css' with { type: 'css' };
4+
5+
export class MyEl extends LitElement {
6+
static readonly styles = [styles];
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:host {
2+
display: block;
3+
color: red;
4+
}

packages/typescript-transform-lit-css/test/typescript-transform-lit-css.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,19 @@ test('typescript-transform-lit-css', async function(assert) {
6262
'handles special chars in CSS',
6363
);
6464

65+
assert.equal(
66+
await getCode('import-attrs/input.js'),
67+
await read('import-attrs/output.js'),
68+
'handles CSS imports with import attributes (with { type: "css" })',
69+
);
70+
71+
await compile(join(FIXTURES_DIR, 'import-attrs-module'));
72+
73+
assert.equal(
74+
await getCode('import-attrs-module/input.js'),
75+
await read('import-attrs-module/output.js'),
76+
'handles CSS imports with import attributes in non-inline mode',
77+
);
78+
6579
assert.end();
6680
});

0 commit comments

Comments
 (0)