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 all 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
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 })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow! You've managed to find a hidden postcss option!

.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 = () => {
sigveio marked this conversation as resolved.
Show resolved Hide resolved
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