Skip to content

Commit 2949578

Browse files
committed
Silence postcss warnings in tests
1 parent d5e0f10 commit 2949578

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

test/helpers/check-fixture.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function read(name, ext) {
1616

1717
module.exports = function(t, file, opts, postcssOpts, warnings) {
1818
opts = Object.assign({ path: "test/fixtures/imports" }, opts)
19+
postcssOpts = Object.assign({ from: undefined }, postcssOpts)
1920
if (typeof file === "string") file = { name: file, ext: ".css" }
2021
const { name, ext } = file
2122

test/import.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test("should not fail with only one absolute import", t => {
2828
const base = "@import url(http://)"
2929
return postcss()
3030
.use(atImport())
31-
.process(base)
31+
.process(base, { from: undefined })
3232
.then(result => {
3333
t.is(result.warnings().length, 0)
3434
t.is(result.css, base)
@@ -39,7 +39,8 @@ test("should not fail with absolute and local import", t => {
3939
return postcss()
4040
.use(atImport())
4141
.process(
42-
"@import url('http://');\n@import 'test/fixtures/imports/foo.css';"
42+
"@import url('http://');\n@import 'test/fixtures/imports/foo.css';",
43+
{ from: undefined }
4344
)
4445
.then(result => t.is(result.css, "@import url('http://');\nfoo{}"))
4546
})
@@ -72,7 +73,9 @@ test("should contain a correct sourcemap", t => {
7273
test("inlined @import should keep PostCSS AST references clean", t => {
7374
return postcss()
7475
.use(atImport())
75-
.process("@import 'test/fixtures/imports/foo.css';\nbar{}")
76+
.process("@import 'test/fixtures/imports/foo.css';\nbar{}", {
77+
from: undefined,
78+
})
7679
.then(result => {
7780
result.root.nodes.forEach(node => t.is(result.root, node.parent))
7881
})
@@ -90,7 +93,7 @@ test(
9093
test("should work with no styles without throwing an error", t => {
9194
return postcss()
9295
.use(atImport())
93-
.process("")
96+
.process("", { from: undefined })
9497
.then(result => {
9598
t.is(result.warnings().length, 0)
9699
})

test/lint.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const processor = postcss().use(atImport())
99

1010
test("should warn when not @charset and not @import statement before", t => {
1111
return Promise.all([
12-
processor.process(`a {} @import "";`),
13-
processor.process(`@media {} @import "";`),
12+
processor.process(`a {} @import "";`, { from: undefined }),
13+
processor.process(`@media {} @import "";`, { from: undefined }),
1414
]).then(results => {
1515
results.forEach(result => {
1616
const warnings = result.warnings()
@@ -30,7 +30,8 @@ test("should warn about all imports after some other CSS declaration", t => {
3030
a {}
3131
@import "a.css";
3232
@import "b.css";
33-
`
33+
`,
34+
{ from: undefined }
3435
)
3536
.then(result => {
3637
t.plan(2)
@@ -44,16 +45,18 @@ test("should warn about all imports after some other CSS declaration", t => {
4445
})
4546

4647
test("should not warn if comments before @import", t => {
47-
return processor.process(`/* skipped comment */ @import "";`).then(result => {
48-
const warnings = result.warnings()
49-
t.is(warnings.length, 1)
50-
t.is(warnings[0].text, `Unable to find uri in '@import ""'`)
51-
})
48+
return processor
49+
.process(`/* skipped comment */ @import "";`, { from: undefined })
50+
.then(result => {
51+
const warnings = result.warnings()
52+
t.is(warnings.length, 1)
53+
t.is(warnings[0].text, `Unable to find uri in '@import ""'`)
54+
})
5255
})
5356

5457
test("should warn if something before comments", t => {
5558
return processor
56-
.process(`a{} /* skipped comment */ @import "";`)
59+
.process(`a{} /* skipped comment */ @import "";`, { from: undefined })
5760
.then(result => {
5861
t.is(result.warnings().length, 1)
5962
})
@@ -75,15 +78,17 @@ test("should not warn when @charset or @import statement before", t => {
7578
})
7679

7780
test("should warn when a user didn't close an import with ;", t => {
78-
return processor.process(`@import url('http://') :root{}`).then(result => {
79-
const warnings = result.warnings()
80-
t.is(warnings.length, 1)
81-
t.is(
82-
warnings[0].text,
83-
"It looks like you didn't end your @import statement correctly. " +
84-
"Child nodes are attached to it."
85-
)
86-
})
81+
return processor
82+
.process(`@import url('http://') :root{}`, { from: undefined })
83+
.then(result => {
84+
const warnings = result.warnings()
85+
t.is(warnings.length, 1)
86+
t.is(
87+
warnings[0].text,
88+
"It looks like you didn't end your @import statement correctly. " +
89+
"Child nodes are attached to it."
90+
)
91+
})
8792
})
8893

8994
test("should warn on invalid url", t => {
@@ -97,7 +102,8 @@ test("should warn on invalid url", t => {
97102
@import url();
98103
@import url('');
99104
@import url("");
100-
`
105+
`,
106+
{ from: undefined }
101107
)
102108
.then(result => {
103109
const warnings = result.warnings()
@@ -113,7 +119,9 @@ test("should warn on invalid url", t => {
113119
})
114120

115121
test("should not warn when a user closed an import with ;", t => {
116-
return processor.process(`@import url('http://');`).then(result => {
117-
t.is(result.warnings().length, 0)
118-
})
122+
return processor
123+
.process(`@import url('http://');`, { from: undefined })
124+
.then(result => {
125+
t.is(result.warnings().length, 0)
126+
})
119127
})

test/plugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ test("should apply plugins to root", t => {
3333
test("should error when value is not an array", t => {
3434
return postcss()
3535
.use(atImport({ plugins: "foo" }))
36-
.process("")
36+
.process("", { from: undefined })
3737
.catch(error => t.is(error.message, "plugins option must be an array"))
3838
})
3939

4040
test("should remain silent when value is an empty array", t => {
4141
return postcss()
4242
.use(atImport({ plugins: [] }))
43-
.process("")
43+
.process("", { from: undefined })
4444
.then(result => t.is(result.css, ""))
4545
})

test/syntax-error.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import atImport from ".."
1010

1111
test("SyntaxError in imported file throws", t => {
1212
return postcss(atImport({ path: "test/fixtures/imports" }))
13-
.process(fs.readFileSync("test/fixtures/syntax-error.css", "utf8"))
13+
.process(fs.readFileSync("test/fixtures/syntax-error.css", "utf8"), {
14+
from: undefined,
15+
})
1416
.then(() => t.fail("should error out"))
1517
.catch(err => t.truthy(err))
1618
})

0 commit comments

Comments
 (0)