diff --git a/jest.config.js b/jest.config.js index dd0cbb03c..47ff0c8bf 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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/', diff --git a/packages/cssnano-utils/src/__tests__/sameParent.test.js b/packages/cssnano-utils/src/__tests__/sameParent.test.js index dfe421430..e5c42a17b 100644 --- a/packages/cssnano-utils/src/__tests__/sameParent.test.js +++ b/packages/cssnano-utils/src/__tests__/sameParent.test.js @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; diff --git a/packages/cssnano/src/__tests__/api.js b/packages/cssnano/src/__tests__/api.js index 80c73c4c4..6fa4086a0 100644 --- a/packages/cssnano/src/__tests__/api.js +++ b/packages/cssnano/src/__tests__/api.js @@ -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); }); } diff --git a/packages/cssnano/src/__tests__/issue26.js b/packages/cssnano/src/__tests__/issue26.js index 62956c353..18cdc6dd7 100644 --- a/packages/cssnano/src/__tests__/issue26.js +++ b/packages/cssnano/src/__tests__/issue26.js @@ -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 }) diff --git a/packages/cssnano/src/__tests__/issue927.js b/packages/cssnano/src/__tests__/issue927.js index 002aaa68f..1d187f9aa 100644 --- a/packages/cssnano/src/__tests__/issue927.js +++ b/packages/cssnano/src/__tests__/issue927.js @@ -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) => { @@ -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)); +}); diff --git a/packages/cssnano/src/__tests__/postcss-normalize-url.js b/packages/cssnano/src/__tests__/postcss-normalize-url.js index 0b2c79fbd..a48f542c1 100644 --- a/packages/cssnano/src/__tests__/postcss-normalize-url.js +++ b/packages/cssnano/src/__tests__/postcss-normalize-url.js @@ -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 } ) ); diff --git a/packages/postcss-minify-selectors/src/__tests__/index.js b/packages/postcss-minify-selectors/src/__tests__/index.js index c8b3b678d..bedf54f0c 100644 --- a/packages/postcss-minify-selectors/src/__tests__/index.js +++ b/packages/postcss-minify-selectors/src/__tests__/index.js @@ -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 */ diff --git a/packages/stylehacks/src/__tests__/api.js b/packages/stylehacks/src/__tests__/api.js index 87a8f21c0..286c10d6d 100644 --- a/packages/stylehacks/src/__tests__/api.js +++ b/packages/stylehacks/src/__tests__/api.js @@ -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 }) @@ -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 }) diff --git a/packages/stylehacks/src/__tests__/issue8.js b/packages/stylehacks/src/__tests__/issue8.js index d61b3716b..f9a834757 100644 --- a/packages/stylehacks/src/__tests__/issue8.js +++ b/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()])