1
1
import { assert } from "chai" ;
2
2
import { skip , suite , test } from "mocha-typescript" ;
3
3
import { postcss } from "opticss" ;
4
+ import { outdent } from "outdent" ;
4
5
5
6
import { CascadingError } from "../../src/errors" ;
6
7
import { assertMultipleErrorsRejection } from "../util/assertError" ;
@@ -13,60 +14,58 @@ const { InvalidBlockSyntax } = require("../util/postcss-helper");
13
14
@suite ( "Block Names" )
14
15
export class BlockNames extends BEMProcessor {
15
16
16
- @test "block names in double quotes fail parse with helpful error " ( ) : Promise < postcss . Result | void > {
17
+ @test "block names in double quotes work " ( ) : Promise < postcss . Result | void > {
17
18
let imports = new MockImportRegistry ( ) ;
18
19
imports . registerSource (
19
20
"foo/bar/imported.css" ,
20
- `:scope { block-name: "snow-flake"; }` ,
21
+ outdent `
22
+ :scope { block-name: "snow-flake"; }
23
+ ` ,
21
24
) ;
22
25
23
26
let filename = "foo/bar/test-block.css" ;
24
- let inputCSS = `@block a-block from "./imported.css";
25
- @block-debug a-block to comment;` ;
27
+ let inputCSS = outdent `
28
+ @block a-block from "./imported.css";
29
+ @block-debug a-block to comment;
30
+ ` ;
26
31
27
- return assertMultipleErrorsRejection (
28
- [
29
- {
30
- type : CascadingError ,
31
- message : "Error in imported block. (foo/bar/test-block.css:1:1)" ,
32
- cause : {
33
- type : InvalidBlockSyntax ,
34
- message : "Illegal block name. '\"snow-flake\"' is not a legal CSS identifier. (foo/bar/imported.css:1:10)" ,
35
- } ,
36
- }
37
- ,
38
- {
39
- type : InvalidBlockSyntax ,
40
- message : `Invalid block debug: No Block named "a-block" found in scope. (foo/bar/test-block.css:2:21)` ,
41
- } ] ,
42
- this . process ( filename , inputCSS , { importer : imports . importer ( ) } ) ) ;
32
+ return this . process ( filename , inputCSS , { importer : imports . importer ( ) } ) . then ( ( result ) => {
33
+ assert . deepEqual (
34
+ result . css . toString ( ) ,
35
+ outdent `
36
+ /* Source: foo/bar/imported.css
37
+ * :scope (.snow-flake)
38
+ */
39
+
40
+ ` ,
41
+ ) ;
42
+ } ) ;
43
43
}
44
44
45
- @test "block names in single quotes fail parse with helpful error " ( ) : Promise < postcss . Result | void > {
45
+ @test "block names in single quotes work " ( ) : Promise < postcss . Result | void > {
46
46
let imports = new MockImportRegistry ( ) ;
47
47
imports . registerSource (
48
48
"foo/bar/imported.css" ,
49
49
`:scope { block-name: 'snow-flake'; }` ,
50
50
) ;
51
51
52
52
let filename = "foo/bar/test-block.css" ;
53
- let inputCSS = `@block imported from "./imported.css";
54
- @block-debug snow-flake to comment;` ;
53
+ let inputCSS = outdent `
54
+ @block snow-flake from "./imported.css";
55
+ @block-debug snow-flake to comment;
56
+ ` ;
55
57
56
- return assertMultipleErrorsRejection (
57
- [ {
58
- type : CascadingError ,
59
- message : "Error in imported block. (foo/bar/test-block.css:1:1)" ,
60
- cause : {
61
- type : InvalidBlockSyntax ,
62
- message : `Illegal block name. \'\'snow-flake\'\' is not a legal CSS identifier. (foo/bar/imported.css:1:10)` ,
63
- } ,
64
- } ,
65
- {
66
- type : InvalidBlockSyntax ,
67
- message : `Invalid block debug: No Block named "snow-flake" found in scope. (foo/bar/test-block.css:2:21)` ,
68
- } ] ,
69
- this . process ( filename , inputCSS , { importer : imports . importer ( ) } ) ) ;
58
+ return this . process ( filename , inputCSS , { importer : imports . importer ( ) } ) . then ( ( result ) => {
59
+ assert . deepEqual (
60
+ result . css . toString ( ) ,
61
+ outdent `
62
+ /* Source: foo/bar/imported.css
63
+ * :scope (.snow-flake)
64
+ */
65
+
66
+ ` ,
67
+ ) ;
68
+ } ) ;
70
69
}
71
70
72
71
@test "block-name property only works in the root ruleset" ( ) {
0 commit comments