diff --git a/src/@types/index.ts b/src/@types/index.ts index cde967af..20b4076d 100644 --- a/src/@types/index.ts +++ b/src/@types/index.ts @@ -43,8 +43,8 @@ export type RTLCSSPlugin = { name: string; priority: number; directives: { - control: Object, - value: Array + control: object, + value: Array }; } diff --git a/src/data/store.ts b/src/data/store.ts index 0d51b2e9..b20d3157 100644 --- a/src/data/store.ts +++ b/src/data/store.ts @@ -106,7 +106,7 @@ const isNotAcceptedStringMap = (stringMap: PluginStringMap[]): boolean => { const isAcceptedProcessDeclarationPlugins = (plugins: DeclarationPlugin[]): boolean => Array.isArray(plugins) && plugins.every((plugin: DeclarationPlugin) => - typeof plugin.name == STRING_TYPE + typeof plugin.name == STRING_TYPE && typeof plugin.priority == NUMBER_TYPE && Array.isArray(plugin.processors) && plugin.processors.every((processor: DeclarationPluginProcessor) => diff --git a/tests/process-declaration-plugins.test.ts b/tests/process-declaration-plugins.test.ts index a92c4892..8016ec9e 100644 --- a/tests/process-declaration-plugins.test.ts +++ b/tests/process-declaration-plugins.test.ts @@ -1,10 +1,10 @@ import postcss from 'postcss'; import postcssRTLCSS from '../src'; -import { PluginOptions, Mode } from '../src/@types'; +import {PluginOptions} from '../src/@types'; import { - readCSSFile, - runTests, - createSnapshotFileName + readCSSFile, + runTests, + createSnapshotFileName } from './utils'; import 'jest-specific-snapshot'; @@ -12,41 +12,41 @@ const BASE_NAME = 'process-declaration-plugins'; runTests({}, (pluginOptions: PluginOptions): void => { - describe(`[[Mode: ${pluginOptions.mode}]]`, (): void => { + describe(`[[Mode: ${pluginOptions.mode}]]`, (): void => { - let input = ''; - - beforeEach(async (): Promise => { - input = input || await readCSSFile(`input-${BASE_NAME}.scss`); - }); - - it('flip background by default', (): void => { - const output = postcss([postcssRTLCSS(pluginOptions)]).process(input); - expect(output.css).toMatchSpecificSnapshot( - createSnapshotFileName(BASE_NAME,'flip', pluginOptions.mode) - ); - expect(output.warnings()).toHaveLength(0); - }); + let input = ''; + + beforeEach(async (): Promise => { + input = input || await readCSSFile(`input-${BASE_NAME}.scss`); + }); + + it('flip background by default', (): void => { + const output = postcss([postcssRTLCSS(pluginOptions)]).process(input); + expect(output.css).toMatchSpecificSnapshot( + createSnapshotFileName(BASE_NAME, 'flip', pluginOptions.mode) + ); + expect(output.warnings()).toHaveLength(0); + }); + + it('use {processDeclarationPlugins} to avoid flipping background', (): void => { + const options: PluginOptions = { + ...pluginOptions, + processDeclarationPlugins: [{ + name: 'avoid-flipping-background', + priority: 99, // above the core RTLCSS plugin which has a priority value of 100 + processors: [{ + expr: /(background|object)(-position(-x)?|-image)?$/i, + action: (prop: string, value: string) => ({prop, value}) + }] + }] + }; + const output = postcss([postcssRTLCSS(options)]).process(input); + expect(output.css).toMatchSpecificSnapshot( + createSnapshotFileName(BASE_NAME, 'noflip', pluginOptions.mode) + ); + expect(output.warnings()).toHaveLength(0); + }); - it('use {processDeclarationPlugins} to avoid flipping background', (): void => { - const options: PluginOptions = { - ...pluginOptions, - processDeclarationPlugins: [{ - name: 'avoid-flipping-background', - priority: 99, // above the core RTLCSS plugin which has a priority value of 100 - processors: [{ - expr: /(background|object)(-position(-x)?|-image)?$/i, - action: (prop: string, value: string) => ({prop, value}) - }] - }] - }; - const output = postcss([postcssRTLCSS(options)]).process(input); - expect(output.css).toMatchSpecificSnapshot( - createSnapshotFileName(BASE_NAME,'noflip', pluginOptions.mode) - ); - expect(output.warnings()).toHaveLength(0); }); - - }); }); \ No newline at end of file