11import fs from 'fs/promises' ;
2- import { ValidationError } from 'jsonschema' ;
32import { describe , expect , it , test , vi } from 'vitest' ;
4- import { expectIsError , expectIsSuccess , testMocksDir } from '../../../ __tests__/fixtures.js' ;
5- import { getBundleManifest , getBundleManifests , resolveAllBundles , resolveSingleBundle } from '../index .js' ;
6- import { MissingTabError , type GetBundleManifestSuccess } from '../types .js' ;
3+ import { expectIsError , expectIsSuccess , testMocksDir } from '../../__tests__/fixtures.js' ;
4+ import { Severity } from '../../types .js' ;
5+ import { getBundleManifest , getBundleManifests , resolveAllBundles , resolveSingleBundle , type GetBundleManifestResult } from '../manifest .js' ;
76
8- vi . mock ( import ( '../../../ getGitRoot.js' ) ) ;
7+ vi . mock ( import ( '../../getGitRoot.js' ) ) ;
98
109describe ( 'Test bundle manifest schema validation succeeds' , ( ) => {
1110 const mockedReadFile = vi . spyOn ( fs , 'readFile' ) ;
@@ -14,8 +13,8 @@ describe('Test bundle manifest schema validation succeeds', () => {
1413 mockedReadFile . mockResolvedValueOnce ( '{ "tabs": [] }' ) ;
1514 mockedReadFile . mockResolvedValueOnce ( '{ "version": "1.0.0" }' ) ;
1615
17- const expected : GetBundleManifestSuccess = {
18- severity : 'success' ,
16+ const expected : GetBundleManifestResult = {
17+ severity : Severity . SUCCESS ,
1918 manifest : {
2019 tabs : [ ] ,
2120 version : '1.0.0'
@@ -31,8 +30,8 @@ describe('Test bundle manifest schema validation succeeds', () => {
3130 mockedReadFile . mockResolvedValueOnce ( '{ "tabs": ["tab0", "tab1"] }' ) ;
3231 mockedReadFile . mockResolvedValueOnce ( '{ "version": "1.0.0" }' ) ;
3332
34- const expected : GetBundleManifestSuccess = {
35- severity : 'success' ,
33+ const expected : GetBundleManifestResult = {
34+ severity : Severity . SUCCESS ,
3635 manifest : {
3736 tabs : [ 'tab0' , 'tab1' ] ,
3837 version : '1.0.0'
@@ -48,8 +47,8 @@ describe('Test bundle manifest schema validation succeeds', () => {
4847 mockedReadFile . mockResolvedValueOnce ( '{ "tabs": ["tab0"] }' ) ;
4948 mockedReadFile . mockResolvedValueOnce ( '{}' ) ;
5049
51- const expected : GetBundleManifestSuccess = {
52- severity : 'success' ,
50+ const expected : GetBundleManifestResult = {
51+ severity : Severity . SUCCESS ,
5352 manifest : {
5453 tabs : [ 'tab0' ]
5554 }
@@ -70,7 +69,7 @@ describe('Test bundle manifest schema validation succeeds', () => {
7069
7170 expect ( result ! . errors . length ) . toEqual ( 1 ) ;
7271 const [ err ] = result ! . errors ;
73- expect ( err ) . toBeInstanceOf ( MissingTabError ) ;
72+ expect ( err ) . toEqual ( 'Unknown tab tab2' ) ;
7473 } ) ;
7574
7675 test ( 'Schema with additional properties' , async ( ) => {
@@ -83,7 +82,7 @@ describe('Test bundle manifest schema validation succeeds', () => {
8382
8483 expect ( result ! . errors . length ) . toEqual ( 1 ) ;
8584 const [ err ] = result ! . errors ;
86- expect ( err ) . toBeInstanceOf ( ValidationError ) ;
85+ expect ( err ) . toMatchInlineSnapshot ( `"instance is not allowed to have the additional property "unknown""` ) ;
8786 } ) ;
8887
8988 test ( 'Schema with invalid requires' , async ( ) => {
@@ -96,7 +95,7 @@ describe('Test bundle manifest schema validation succeeds', () => {
9695
9796 expect ( result ! . errors . length ) . toEqual ( 1 ) ;
9897 const [ err ] = result ! . errors ;
99- expect ( err ) . toBeInstanceOf ( ValidationError ) ;
98+ expect ( err ) . toMatchInlineSnapshot ( `"instance.requires is not one of enum values: 1,2,3,4"` ) ;
10099 } ) ;
101100} ) ;
102101
@@ -112,7 +111,6 @@ describe('Test getBundleManifests', () => {
112111
113112 const result = await getBundleManifests ( '/src/bundles' ) ;
114113 expectIsError ( result . severity ) ;
115- expect ( result . errors [ 0 ] ) . toBe ( errorObject ) ;
116114 } ) ;
117115} ) ;
118116
@@ -141,7 +139,7 @@ describe('Test resolveSingleBundle', () => {
141139 const resolved = await resolveSingleBundle ( path ) ;
142140 expect ( resolved ) . toMatchObject ( {
143141 severity : 'error' ,
144- errors : [ expect . any ( Error ) ]
142+ errors : [ expect . any ( String ) ]
145143 } ) ;
146144
147145 const stats = await fs . stat ( path ) ;
0 commit comments