Skip to content

Commit

Permalink
test: fix misc. test warnings (#1161)
Browse files Browse the repository at this point in the history
* test: fix misc. test warnings

- Replace deprecated postcss.plugin syntax
- Add { from: undefined } option to prevent warnings
- Dummy workaround for calling postcss w/o plugins

* test(cssnano): ignore test helpers in coverage rep

* test(cssnano-utils): suppress plugin warning

* test(cssnano): leave a test for old plugin syntax
  • Loading branch information
sigveio committed Jul 8, 2021
1 parent 629918c commit 095f901
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 45 deletions.
2 changes: 2 additions & 0 deletions jest.config.js
Expand Up @@ -4,6 +4,8 @@ module.exports = {
'packages/*/src/**/*.js',
'!packages/postcss-colormin/src/generate.js',
'!packages/postcss-reduce-initial/src/acquire.js',
'!packages/cssnano/src/__tests__/_processCss.js',
'!packages/cssnano/src/__tests__/_webpack.config.js',
],
testPathIgnorePatterns: [
'/node_modules/',
Expand Down
29 changes: 19 additions & 10 deletions packages/cssnano-utils/src/__tests__/sameParent.test.js
Expand Up @@ -3,7 +3,7 @@ import sameParent from '../sameParent';

test('should calculate same parent', () => {
return postcss()
.process('h1 {} h2 {}', { from: undefined })
.process('h1 {} h2 {}', { from: undefined, hideNothingWarning: true })
.then((result) => {
const h1 = result.root.nodes[0];
const h2 = result.root.nodes[1];
Expand All @@ -14,7 +14,7 @@ test('should calculate same parent', () => {

test('should calculate same parent (detached nodes)', () => {
return postcss()
.process('h1 {} h2 {}', { from: undefined })
.process('h1 {} h2 {}', { from: undefined, hideNothingWarning: true })
.then((result) => {
const h1 = result.root.nodes[0];
const h2 = result.root.nodes[1];
Expand All @@ -28,7 +28,10 @@ test('should calculate same parent (detached nodes)', () => {

test('should calculate same parent (at rules)', () => {
return postcss()
.process('@media screen{h1 {} h2 {}}', { from: undefined })
.process('@media screen{h1 {} h2 {}}', {
from: undefined,
hideNothingWarning: true,
})
.then((result) => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[0].nodes[1];
Expand All @@ -39,7 +42,10 @@ test('should calculate same parent (at rules)', () => {

test('should calculate same parent (multiple at rules)', () => {
return postcss()
.process('@media screen{h1 {}} @media screen{h2 {}}', { from: undefined })
.process('@media screen{h1 {}} @media screen{h2 {}}', {
from: undefined,
hideNothingWarning: true,
})
.then((result) => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0];
Expand All @@ -50,7 +56,10 @@ test('should calculate same parent (multiple at rules)', () => {

test('should calculate same parent (multiple at rules (uppercase))', () => {
return postcss()
.process('@media screen{h1 {}} @MEDIA screen{h2 {}}', { from: undefined })
.process('@media screen{h1 {}} @MEDIA screen{h2 {}}', {
from: undefined,
hideNothingWarning: true,
})
.then((result) => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0];
Expand All @@ -74,7 +83,7 @@ test('should calculate same parent (nested at rules)', () => {
}
}
`,
{ from: undefined }
{ from: undefined, hideNothingWarning: true }
)
.then((result) => {
const h1 = result.root.nodes[0].nodes[0].nodes[0];
Expand All @@ -99,7 +108,7 @@ test('should calculate not same parent (nested at rules)', () => {
}
}
`,
{ from: undefined }
{ from: undefined, hideNothingWarning: true }
)
.then((result) => {
const h1 = result.root.nodes[0].nodes[0].nodes[0];
Expand All @@ -124,7 +133,7 @@ test('should calculate not same parent (nested at rules) (2)', () => {
}
}
`,
{ from: undefined }
{ from: undefined, hideNothingWarning: true }
)
.then((result) => {
const h1 = result.root.nodes[0].nodes[0].nodes[0];
Expand All @@ -147,7 +156,7 @@ test('should calculate not same parent (nested at rules) (3)', () => {
}
}
`,
{ from: undefined }
{ from: undefined, hideNothingWarning: true }
)
.then((result) => {
const h1 = result.root.nodes[0].nodes[0];
Expand All @@ -170,7 +179,7 @@ test('should calculate not same parent (nested at rules) (4)', () => {
}
}
`,
{ from: undefined }
{ from: undefined, hideNothingWarning: true }
)
.then((result) => {
const h1 = result.root.nodes[0].nodes[0];
Expand Down
2 changes: 1 addition & 1 deletion packages/cssnano/src/__tests__/api.js
Expand Up @@ -6,7 +6,7 @@ function pluginMacro(instance) {
const min = 'h1{color:#fff}';

return () =>
instance.process(css).then((result) => {
instance.process(css, { from: undefined }).then((result) => {
expect(result.css).toBe(min);
});
}
Expand Down
21 changes: 12 additions & 9 deletions packages/cssnano/src/__tests__/issue26.js
Expand Up @@ -24,17 +24,20 @@ const fixture = `
const expected = `@media print{.test{-webkit-border-radius:0;border-radius:0;-webkit-box-shadow:none;box-shadow:none}}.test{width:500px}`;

test('it should compress whitespace after node.clone()', () => {
const processor = postcss([
postcss.plugin('cloner', () => {
return (css) => {
css.walkAtRules((rule) => {
css.prepend(rule.clone());
const plugin = () => {
return {
postcssPlugin: 'cloner',
Once(root) {
root.walkAtRules((rule) => {
root.prepend(rule.clone());
rule.remove();
});
};
}),
nano(),
]);
},
};
};
plugin.postcss = true;

const processor = postcss([plugin, nano()]);

return processor
.process(fixture, { from: undefined })
Expand Down
23 changes: 22 additions & 1 deletion packages/cssnano/src/__tests__/issue927.js
Expand Up @@ -12,7 +12,7 @@ p{

const expected = `div{grid-column:span 2}p{column-count:2}`;

test('it should compress the columns', () => {
test('it should compress the columns (old plugin syntax)', () => {
const processor = postcss([
postcss.plugin('cloner', () => {
return (css) => {
Expand All @@ -29,3 +29,24 @@ test('it should compress the columns', () => {
.process(fixture, { from: undefined })
.then((r) => expect(r.css).toBe(expected));
});

test('it should compress the columns (new plugin syntax)', () => {
const plugin = () => {
return {
postcssPlugin: 'cloner',
Once(root) {
root.walkAtRules((rule) => {
root.prepend(rule.clone());
rule.remove();
});
},
};
};
plugin.postcss = true;

const processor = postcss([plugin, nano()]);

return processor
.process(fixture, { from: undefined })
.then((r) => expect(r.css).toBe(expected));
});
2 changes: 1 addition & 1 deletion packages/cssnano/src/__tests__/postcss-normalize-url.js
Expand Up @@ -151,7 +151,7 @@ test(
processCss(
'@namespace islands url("http://bar.yandex.ru/ui/islands");',
'@namespace islands "http://bar.yandex.ru/ui/islands";',
{ discardUnused: { namespace: false } }
{ discardUnused: { namespace: false }, from: undefined }
)
);

Expand Down
22 changes: 13 additions & 9 deletions packages/postcss-minify-selectors/src/__tests__/index.js
Expand Up @@ -480,17 +480,21 @@ test('should handle selectors from other plugins', () => {
return result;
}

const toModules = postcss.plugin('toModules', () => {
return (css) => {
css.walkRules((rule) => {
rule.selectors = rule.selectors.map((selector) => {
const slice = selector.slice(1);

return `.${encode(slice).slice(0, 7)}__${slice}`;
const toModules = () => {
return {
postcssPlugin: 'toModules',
Once(root) {
root.walkRules((rule) => {
rule.selectors = rule.selectors.map((selector) => {
const slice = selector.slice(1);

return `.${encode(slice).slice(0, 7)}__${slice}`;
});
});
});
},
};
});
};
toModules.postcss = true;

const css = `.test, /* comment #1 - this comment breaks stuff */
.test:hover { /* comment #2 - ...but this comment is fine */
Expand Down
24 changes: 14 additions & 10 deletions packages/stylehacks/src/__tests__/api.js
Expand Up @@ -49,15 +49,17 @@ test('should use the postcss plugin api', () => {
test('should have a separate detect method', () => {
let counter = 0;

let plugin = postcss.plugin('test', () => {
return (css) => {
css.walkDecls((decl) => {
const plugin = () => {
return {
postcssPlugin: 'test',
Declaration(decl) {
if (stylehacks.detect(decl)) {
counter++;
}
});
},
};
});
};
plugin.postcss = true;

return postcss(plugin)
.process('h1 { _color: red; =color: black }', { from: undefined })
Expand All @@ -67,15 +69,17 @@ test('should have a separate detect method', () => {
test('should have a separate detect method (2)', () => {
let counter = 0;

let plugin = postcss.plugin('test', () => {
return (css) => {
css.walkRules((rule) => {
const plugin = () => {
return {
postcssPlugin: 'test',
Rule(rule) {
if (stylehacks.detect(rule)) {
counter++;
}
});
},
};
});
};
plugin.postcss = true;

return postcss(plugin)
.process('h1 { _color: red; =color: black }', { from: undefined })
Expand Down
14 changes: 10 additions & 4 deletions packages/stylehacks/src/__tests__/issue8.js
@@ -1,9 +1,15 @@
import postcss, { plugin, decl } from 'postcss';
import postcss, { decl } from 'postcss';
import stylehacks from '..';

const insertZoom = plugin('insertZoom', () => {
return (css) => css.first.append(decl({ prop: '*zoom', value: '1' }));
});
const insertZoom = () => {
return {
postcssPlugin: 'insertZoom',
Once(root) {
root.first.append(decl({ prop: '*zoom', value: '1' }));
},
};
};
insertZoom.postcss = true;

test('should remove star hack from plugins like lost', () => {
return postcss([insertZoom(), stylehacks()])
Expand Down

0 comments on commit 095f901

Please sign in to comment.