Skip to content

Commit

Permalink
add tests for improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tompascall committed Oct 5, 2019
1 parent d41e498 commit 425640d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
6 changes: 3 additions & 3 deletions build/pre-processors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/pre-processors.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"jest": "^24.9.0",
"node-sass": "^4.12.0",
"riot": "^4.5.0",
"riot-jest-transformer": "6.0.3"
"riot-jest-transformer": "^6.0.4"
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2"
Expand Down
40 changes: 38 additions & 2 deletions src/__tests__/pre-processors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
import {
getRjtConfig,
getRegistrationOptions,
getCacheOption,
registerPreProcessors,
tryRegistrations,
} from '../pre-processors';
import mockScssPreprocessor from '../__mocks__/mock-scss-preprocessor';
import { registerPreprocessor } from '@riotjs/compiler';
import { TransformerConfig, RegistrationOptions, RiotPreprocessorType } from '../types';
import {
TransformerConfig,
TransformConfig,
RegistrationOptions,
RiotPreprocessorType
} from '../types';

describe('Pre-processors', () => {
describe('getRjtConfig', () => {
it('should return undefined if no riot-jest-transformer config', () => {
// @ts-ignore: testing inappropriate transform config
expect(getRjtConfig(['pattern', 'other transformer'])).toBe(undefined);
});

it('should return rjt config', () => {
const rjtConfig: TransformConfig = [
['pattern', 'other transformer'],
['pattern', 'riot-jest-transformer'],
];
expect(getRjtConfig(rjtConfig)).toEqual(['pattern', 'riot-jest-transformer']);
});
});

describe('getRegistrationOptions', () => {
it('should be a function', () => {
expect(typeof getRegistrationOptions).toBe('function');
});

it('should return null if no array', () => {
const config = {
transform: {},
rootDir: ''
};
// @ts-ignore: testing inappropriate config
expect(getRegistrationOptions(config)).toBe(null);
});

it('should return null if no options object \
in riot-jest-transformer config', () => {
const config: TransformerConfig = {
Expand Down Expand Up @@ -61,7 +91,13 @@ describe('Pre-processors', () => {
});

describe('getCacheOption', () => {
it('should return true if clearCache is not defined', () => {
it('should return false if config is not an array', () => {
const config = {};
// @ts-ignore: testing inappropriate config
expect(getCacheOption(config)).toBe(false);
});

it('should return false if clearCache is not defined', () => {
const config: TransformerConfig = {
transform: [
['filePattern1', 'modulePath'],
Expand Down
2 changes: 1 addition & 1 deletion src/pre-processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getRegistrationOptions = (config: TransformerConfig) => {
return null;
};

const getRjtConfig = (transform: TransformConfig) =>
export const getRjtConfig = (transform: TransformConfig) =>
transform.find(entry =>
entry[TRANSFORMER_PATH].includes('riot-jest-transformer'));

Expand Down

0 comments on commit 425640d

Please sign in to comment.