Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix misc. test warnings #1161

Merged
merged 4 commits into from Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
ludofischer marked this conversation as resolved.
Show resolved Hide resolved
'!packages/cssnano/src/__tests__/_webpack.config.js',
],
testPathIgnorePatterns: [
'/node_modules/',
Expand Down
27 changes: 17 additions & 10 deletions packages/cssnano-utils/src/__tests__/sameParent.test.js
@@ -1,8 +1,15 @@
import postcss from 'postcss';
import sameParent from '../sameParent';

const plugin = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there another way to suppress the warnings? In fact we want postcss to do nothing here. I think adding more code to the test does not help with clarity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... my rationale was that when I opened up that file, not knowing the code at all, it was not clear to me at first that you did in fact not want postcss to do anything. So although the dummy plugin at the top of the file does add a little bit of code - could it not also help point out the intention by explicitly passing in a "dummy" instead of nothing?

I didn't see any obvious alternative way (e.g. an option for postcss), but admittedly I also didn't look super hard. Would be happy to have another look though

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think just adding a comment to explain what's going on is the best solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright - I'll look into it a bit more thoroughly and see if I find a better solution to suppress the warnings then :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so there is actually an option to suppress it:

https://github.com/postcss/postcss/blob/10d974f81d2b925a9e8c0912857dcda1bf6720c0/lib/processor.js#L19

So;

test('should calculate same parent', () => {
  return postcss()
    .process('h1 {} h2 {}', { from: undefined, hideNothingWarning: true })
    .then((result) => {
      (...)
    });
});

Works!

return {
postcssPlugin: 'dummy',
};
};
plugin.postcss = true;

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

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

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

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

test('should calculate same parent (multiple at rules (uppercase))', () => {
return postcss()
return postcss(plugin)
.process('@media screen{h1 {}} @MEDIA screen{h2 {}}', { from: undefined })
.then((result) => {
const h1 = result.root.nodes[0].nodes[0];
Expand All @@ -60,7 +67,7 @@ test('should calculate same parent (multiple at rules (uppercase))', () => {
});

test('should calculate same parent (nested at rules)', () => {
return postcss()
return postcss(plugin)
.process(
`
@media screen {
Expand All @@ -85,7 +92,7 @@ test('should calculate same parent (nested at rules)', () => {
});

test('should calculate not same parent (nested at rules)', () => {
return postcss()
return postcss(plugin)
.process(
`
@media screen {
Expand All @@ -110,7 +117,7 @@ test('should calculate not same parent (nested at rules)', () => {
});

test('should calculate not same parent (nested at rules) (2)', () => {
return postcss()
return postcss(plugin)
.process(
`
@media print {
Expand All @@ -135,7 +142,7 @@ test('should calculate not same parent (nested at rules) (2)', () => {
});

test('should calculate not same parent (nested at rules) (3)', () => {
return postcss()
return postcss(plugin)
.process(
`
@supports(pointer: course) {
Expand All @@ -158,7 +165,7 @@ test('should calculate not same parent (nested at rules) (3)', () => {
});

test('should calculate not same parent (nested at rules) (4)', () => {
return postcss()
return postcss(plugin)
.process(
`
@media screen {
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
21 changes: 12 additions & 9 deletions packages/cssnano/src/__tests__/issue927.js
Expand Up @@ -13,17 +13,20 @@ p{
const expected = `div{grid-column:span 2}p{column-count:2}`;

test('it should compress the columns', () => {
const processor = postcss([
postcss.plugin('cloner', () => {
return (css) => {
css.walkAtRules((rule) => {
css.prepend(rule.clone());
const plugin = () => {
sigveio marked this conversation as resolved.
Show resolved Hide resolved
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
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