diff --git a/README.md b/README.md index 204b458..39edcba 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ Most development tasks can be run directly from `npm` or via `make` wrapper reci | Run tests with coverage | `npm run cover` | `make cover` | | Build documentation | `npm run docs` | `make docs` | +Note that the some of the tests require `python3` and the Python packages `matplotlib` and `Pillow` to be installed. + ## 🙏 Acknowledgments Many thanks to the nteract community for [`kernelspecs`](https://github.com/nteract/kernelspecs) and diff --git a/src/index.test.ts b/src/index.test.ts index 1b34dad..f3e21ac 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -171,7 +171,9 @@ import sys; sys.stderr.write('An error!') expect(chunk.errors).toEqual([ schema.codeError({ errorMessage: 'An error!' }), ]) - expect(chunk.outputs).toEqual([]) + expect(chunk.outputs).toEqual([ + 9, // The write() returns the number of bytes written + ]) }) test('errors', async () => { @@ -269,6 +271,24 @@ describe('unbundle', () => { } }) + test('vega', () => { + const image = jupita.unbundle({ + 'application/vnd.vegalite.v4+json': {}, + }) + expect(schema.isA('ImageObject', image)).toBe(true) + if (schema.isA('ImageObject', image)) { + expect(image.content).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + mediaType: 'application/vnd.vegalite.v4+json', + spec: {}, + }), + ]) + ) + expect(image.contentUrl).toMatch(`https://via.placeholder.com`) + } + }) + test.each([['image/png'], ['image/jpeg'], ['image/gif']])( '%s', (mediaType) => { diff --git a/src/index.ts b/src/index.ts index 571dbb8..0497b0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -464,6 +464,27 @@ export class Jupita extends Listener { }) } + for (const mediaType of [ + 'application/vnd.vega.v1+json', + 'application/vnd.vega.v2+json', + 'application/vnd.vega.v3+json', + 'application/vnd.vega.v4+json', + 'application/vnd.vega.v5+json', + 'application/vnd.vegalite.v1+json', + 'application/vnd.vegalite.v2+json', + 'application/vnd.vegalite.v3+json', + 'application/vnd.vegalite.v4+json', + ]) { + const vega = bundle[mediaType] + if (vega !== undefined) { + return schema.imageObject({ + content: [{ mediaType, spec: vega }], + contentUrl: + 'https://via.placeholder.com/400x60?text=Unable%20to%20render%20Vega%20output', + }) + } + } + for (const mediaType of ['image/png', 'image/jpeg', 'image/gif']) { const image = bundle[mediaType] if (image !== undefined) {