Skip to content

Commit

Permalink
Added test for runFixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ritave committed Jul 23, 2024
1 parent 559d8c0 commit e7313f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/snaps-utils/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 99.73,
"functions": 98.9,
"lines": 99.11,
"statements": 96.02
"lines": 99.43,
"statements": 96.31
}
28 changes: 28 additions & 0 deletions packages/snaps-utils/src/manifest/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getSnapManifest,
getMockLocalizationFile,
getMockSnapFilesWithUpdatedChecksum,
getMockSnapFiles,
} from '../test-utils';
import { NpmSnapFileNames } from '../types';
import {
Expand All @@ -20,8 +21,11 @@ import {
getSnapIcon,
getSnapSourceCode,
getWritableManifest,
runFixes,
} from './manifest';
import type { SnapManifest } from './validation';
import { runValidators } from './validator';
import type { ValidatorMeta } from './validator-types';

jest.mock('fs');

Expand Down Expand Up @@ -286,6 +290,30 @@ describe('checkManifest', () => {
});
});

describe('runFixes', () => {
it('returns correctly if fixing fails', async () => {
// A rule that is fixable but always fails
// This will force the runFixes to run more than MAX_ATTEMPTS
const rule: ValidatorMeta = {
severity: 'error',
semanticCheck(_, context) {
context.report('Always fail', (files) => files);
},
};

const files = getMockSnapFiles();

const validatorResults = await runValidators(files, [rule]);
const fixesResults = await runFixes(validatorResults, [rule]);

expect(fixesResults).toStrictEqual({
files,
updated: false,
reports: [{ severity: 'error', message: 'Always fail' }],
});
});
});

describe('getSnapSourceCode', () => {
beforeEach(async () => {
await resetFileSystem();
Expand Down

0 comments on commit e7313f5

Please sign in to comment.