1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 13:47:06 +01:00
metamask-extension/development/fitness-functions/rules/javascript-additions.test.ts

52 lines
1.7 KiB
TypeScript
Raw Normal View History

import {
generateModifyFilesDiff,
generateCreateFileDiff,
} from '../common/test-data';
import { preventJavaScriptFileAdditions } from './javascript-additions';
describe('preventJavaScriptFileAdditions()', (): void => {
it('should pass when receiving an empty diff', (): void => {
const testDiff = '';
const hasRulePassed = preventJavaScriptFileAdditions(testDiff);
expect(hasRulePassed).toBe(true);
});
it('should pass when receiving a diff with a new TS file on the shared folder', (): void => {
const testDiff = [
generateModifyFilesDiff('new-file.ts', 'foo', 'bar'),
generateModifyFilesDiff('old-file.js', undefined, 'pong'),
generateCreateFileDiff('shared/test.ts', 'yada yada yada yada'),
].join('');
const hasRulePassed = preventJavaScriptFileAdditions(testDiff);
expect(hasRulePassed).toBe(true);
});
it('should not pass when receiving a diff with a new JS file on the shared folder', (): void => {
const testDiff = [
generateModifyFilesDiff('new-file.ts', 'foo', 'bar'),
generateModifyFilesDiff('old-file.js', undefined, 'pong'),
generateCreateFileDiff('shared/test.js', 'yada yada yada yada'),
].join('');
const hasRulePassed = preventJavaScriptFileAdditions(testDiff);
expect(hasRulePassed).toBe(false);
});
it('should not pass when receiving a diff with a new JSX file on the shared folder', (): void => {
const testDiff = [
generateModifyFilesDiff('new-file.ts', 'foo', 'bar'),
generateModifyFilesDiff('old-file.js', undefined, 'pong'),
generateCreateFileDiff('shared/test.jsx', 'yada yada yada yada'),
].join('');
const hasRulePassed = preventJavaScriptFileAdditions(testDiff);
expect(hasRulePassed).toBe(false);
});
});