Skip to content

Commit 3d4725e

Browse files
committed
fleshing out the tests a bit further
1 parent ab4068d commit 3d4725e

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ exports['default'] = function (css) {
8383
}
8484
});
8585
importAliases.push({ path: path, imports: imports });
86-
atRule.removeSelf();
86+
atRule.remove();
8787
}
8888
});
8989

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default css => {
4949
}
5050
})
5151
importAliases.push({path, imports})
52-
atRule.removeSelf()
52+
atRule.remove()
5353
}
5454
})
5555

test/index.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,52 @@ const test = (input, expected) => {
1212

1313
describe('constants', () => {
1414
it('should pass through an empty string', () => {
15-
test('','')
15+
test('', '')
1616
})
1717

1818
it('should export a constant', () => {
19-
test('@define red blue;',':export {\n red: blue\n}')
19+
test('@define red blue;', ':export {\n red: blue\n}')
20+
})
21+
22+
it('should export a more complex constant', () => {
23+
test('@define small (max-width: 599px);', ':export {\n small: (max-width: 599px)\n}')
24+
})
25+
26+
it('should replace constants within the file', () => {
27+
test('@define blue red; .foo { color: blue; }', ':export {\n blue: red;\n}\n.foo { color: red; }')
28+
})
29+
30+
it('should import a simple constant', () => {
31+
test('@import red from "./colors.css";', ':import("./colors.css") {\n i__const_red_0: red\n}')
32+
})
33+
34+
it('should import a simple constant and replace usages', () => {
35+
test('@import red from "./colors.css"; .foo { color: red; }', ':import("./colors.css") {\n i__const_red_1: red;\n}\n.foo { color: i__const_red_1; }')
36+
})
37+
38+
it('should import and alias a constant and replace usages', () => {
39+
test('@import blue as red from "./colors.css"; .foo { color: red; }', ':import("./colors.css") {\n i__const_red_2: blue;\n}\n.foo { color: i__const_red_2; }')
40+
})
41+
42+
it('should import multiple from a single file', () => {
43+
test(
44+
`@import blue, red from "./colors.css";
45+
.foo { color: red; }
46+
.bar { color: blue }`,
47+
`:import("./colors.css") {
48+
i__const_blue_3: blue;
49+
i__const_red_4: red;
50+
}
51+
.foo { color: i__const_red_4; }
52+
.bar { color: i__const_blue_3 }`)
53+
})
54+
55+
it('should import from a definition', () => {
56+
test(
57+
'@define colors: "./colors.css"; @import red from colors;',
58+
':export {\n colors: "./colors.css"\n}\n' +
59+
':import("./colors.css") {\n i__const_red_5: red\n}'
60+
)
2061
})
2162
})
2263

0 commit comments

Comments
 (0)