Skip to content

Commit 6f34a3c

Browse files
committed
Add tests for nesting
1 parent 481a5e7 commit 6f34a3c

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/helpers/__tests__/__snapshots__/getDtsSnapshot.test.ts.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,56 @@ export const __cssModule: true;
328328
export type AllClassNames = 'foo' | 'bar' | 'baz' | 'col-1' | 'col-2' | 'col-3' | 'local-class-1' | 'inside-local' | 'inside-1-name-2' | 'inside-2-name-1';"
329329
`;
330330

331+
exports[`utils / cssSnapshots with file 'postcss.module.css' createExports should create an exports file 1`] = `
332+
"declare let classes: {
333+
'classA': string;
334+
'nestedA': string;
335+
'nested_B': string;
336+
'deeplyNested': string;
337+
'nested-c': string;
338+
'parent': string;
339+
};
340+
export default classes;
341+
export let classA: string;
342+
export let nestedA: string;
343+
export let nested_B: string;
344+
export let deeplyNested: string;
345+
export let parent: string;
346+
"
347+
`;
348+
349+
exports[`utils / cssSnapshots with file 'postcss.module.css' getCssExports should return an object matching expected CSS 1`] = `
350+
{
351+
"classA": "classA",
352+
"deeplyNested": "deeplyNested",
353+
"nested-c": "nested-c",
354+
"nestedA": "nestedA",
355+
"nested_B": "nested_B",
356+
"parent": "parent",
357+
}
358+
`;
359+
360+
exports[`utils / cssSnapshots with file 'postcss.module.css' with a custom template should transform the generated dts 1`] = `
361+
"/* eslint-disable */
362+
declare let classes: {
363+
'classA': string;
364+
'nestedA': string;
365+
'nested_B': string;
366+
'deeplyNested': string;
367+
'nested-c': string;
368+
'parent': string;
369+
};
370+
export default classes;
371+
export let classA: string;
372+
export let nestedA: string;
373+
export let nested_B: string;
374+
export let deeplyNested: string;
375+
export let parent: string;
376+
377+
export const __cssModule: true;
378+
export type AllClassNames = 'classA' | 'nestedA' | 'nested_B' | 'deeplyNested' | 'nested-c' | 'parent';"
379+
`;
380+
331381
exports[`utils / cssSnapshots with file 'test.module.css' createExports should create an exports file 1`] = `
332382
"declare let classes: {
333383
'classA': string;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.classA {
2+
.nestedA {
3+
color: rebeccapurple;
4+
}
5+
.nested_B {
6+
.deeplyNested {
7+
color: rebeccapurple;
8+
}
9+
}
10+
11+
/* https://www.w3.org/TR/css-nesting-1/ */
12+
& .nested-c {
13+
color: rebeccapurple;
14+
}
15+
.parent & {
16+
color: rebeccapurple;
17+
}
18+
}

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readFileSync } from 'fs';
22
import { join } from 'path';
33
import postcssImportSync from 'postcss-import-sync2';
4+
import postcssPresetEnv from 'postcss-preset-env';
45
import tsModule from 'typescript/lib/tsserverlibrary';
56
import { CSSExportsWithSourceMap, getCssExports } from '../getCssExports';
67
import { createDtsExports } from '../createDtsExports';
@@ -16,6 +17,7 @@ const testFileNames = [
1617
'import.module.css',
1718
'import.module.less',
1819
'import.module.styl',
20+
'postcss.module.css',
1921
'test.module.css',
2022
'test.module.less',
2123
'test.module.sass',
@@ -35,6 +37,12 @@ const compilerOptions: tsModule.CompilerOptions = {};
3537
const processor = getProcessor([
3638
// For testing PostCSS import support/functionality.
3739
postcssImportSync(),
40+
postcssPresetEnv({
41+
stage: 3,
42+
features: {
43+
'nesting-rules': true,
44+
},
45+
}),
3846
]);
3947

4048
describe('utils / cssSnapshots', () => {

0 commit comments

Comments
 (0)