diff --git a/packages/utils/jest.config.js b/packages/utils/jest.config.js index dd0f828822..fc4b6ff6d4 100644 --- a/packages/utils/jest.config.js +++ b/packages/utils/jest.config.js @@ -15,10 +15,10 @@ module.exports = { coverageReporters: ['clover', 'json', 'lcov', 'text', 'json-summary'], coverageThreshold: { global: { - branches: 86.05, - functions: 97, - lines: 96.68, - statements: 96.76, + branches: 85.64, + functions: 97.19, + lines: 96.63, + statements: 96.7, }, }, moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], diff --git a/packages/utils/src/types.test.ts b/packages/utils/src/types.test.ts new file mode 100644 index 0000000000..54686a746a --- /dev/null +++ b/packages/utils/src/types.test.ts @@ -0,0 +1,107 @@ +import { + assertIsNpmSnapPackageJson, + assertIsSnapManifest, + isNpmSnapPackageJson, + isSnapManifest, +} from './types'; +import { getPackageJson, getSnapManifest } from './test-utils'; + +describe('isNpmSnapPackageJson', () => { + it('returns true for a valid package.json', () => { + expect(isNpmSnapPackageJson(getPackageJson())).toBe(true); + }); + + it.each([ + true, + false, + null, + undefined, + 0, + 1, + '', + 'foo', + [], + {}, + { name: 'foo' }, + { version: '1.0.0' }, + getPackageJson({ name: 'foo bar' }), + ])('returns false for an invalid package.json', (value) => { + expect(isNpmSnapPackageJson(value)).toBe(false); + }); +}); + +describe('assertIsNpmSnapPackageJson', () => { + it('does not throw for a valid package.json', () => { + expect(() => assertIsNpmSnapPackageJson(getPackageJson())).not.toThrow(); + }); + + it.each([ + true, + false, + null, + undefined, + 0, + 1, + '', + 'foo', + [], + {}, + { name: 'foo' }, + { version: '1.0.0' }, + getPackageJson({ name: 'foo bar' }), + ])('throws for an invalid package.json', (value) => { + expect(() => assertIsNpmSnapPackageJson(value)).toThrow( + '"package.json" is invalid:', + ); + }); +}); + +describe('isSnapManifest', () => { + it('returns true for a valid snap manifest', () => { + expect(isSnapManifest(getSnapManifest())).toBe(true); + }); + + it.each([ + true, + false, + null, + undefined, + 0, + 1, + '', + 'foo', + [], + {}, + { name: 'foo' }, + { version: '1.0.0' }, + getSnapManifest({ version: 'foo bar' }), + ])('returns false for an invalid snap manifest', (value) => { + expect(isSnapManifest(value)).toBe(false); + }); +}); + +describe('assertIsSnapManifest', () => { + it('does not throw for a valid snap manifest', () => { + expect(() => assertIsSnapManifest(getSnapManifest())).not.toThrow(); + }); + + it.each([ + true, + false, + null, + undefined, + 0, + 1, + '', + 'foo', + [], + {}, + { name: 'foo' }, + { version: '1.0.0' }, + getSnapManifest({ version: 'foo bar' }), + ])('throws for an invalid snap manifest', (value) => { + expect(() => assertIsSnapManifest(value)).toThrow( + '"snap.manifest.json" is invalid:', + ); + }); +});