Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix lint
  • Loading branch information
aleen42 authored and elchininet committed May 21, 2024
commit dd78fd02c406bb9c8781732cf1ec61239863dd21
4 changes: 2 additions & 2 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export type RTLCSSPlugin = {
name: string;
priority: number;
directives: {
control: Object,
value: Array<Object>
control: object,
value: Array<object>
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/data/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
74 changes: 37 additions & 37 deletions tests/process-declaration-plugins.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
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';

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<void> => {
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<void> => {
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);
});

});

});