Skip to content
Snippets Groups Projects
Commit 7216f972 authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

Repair tests

parent 867770f7
No related branches found
No related tags found
No related merge requests found
import request from 'supertest'
import { expect } from 'chai'
import { generateSimpleViteManifest, mockApp, mockConfig, mockFetch } from '../spec/util.js'
import { brotliParser, generateSimpleViteManifest, mockApp, mockConfig, mockFetch } from '../spec/util.js'
import * as td from 'testdouble'
import { getRedisKey } from '../src/util.js'
import zlib from 'node:zlib'
describe('File caching service', function () {
let app
......@@ -26,13 +27,14 @@ describe('File caching service', function () {
})
it('caches manifest data', async function () {
const response = await request(app.server).get('/manifests')
const response = await request(app.server).get('/manifests').parse(brotliParser)
expect(response.statusCode).to.equal(200)
const version = response.headers.version
const { client } = await import('../src/redis.js')
expect(await client.get(getRedisKey({ version, name: 'viteManifests' }))).to.equal('{"index.html":{"file":"index.html","meta":{"baseUrl":"http://ui-server/"}}}')
expect(await client.get(getRedisKey({ version, name: 'oxManifests' }))).to.equal('[]')
const redisData = await client.getBuffer(getRedisKey({ version, name: 'oxManifests:body' }))
expect(zlib.brotliDecompressSync(redisData || '').toString()).to.equal('[]')
})
it('caches html files', async function () {
......
import request from 'supertest'
import { generateSimpleViteManifest, mockApp, mockConfig, mockFetch, mockRedis } from './util.js'
import { brotliParser, generateSimpleViteManifest, mockApp, mockConfig, mockFetch, mockRedis } from './util.js'
import fs from 'fs'
import { expect } from 'chai'
import * as td from 'testdouble'
......@@ -350,7 +350,7 @@ describe('File caching service', function () {
expect(spy.callCount).to.equal(0)
const [res1, res2] = await Promise.all([
request(app.server).get('/manifests'),
request(app.server).get('/manifests').parse(brotliParser),
request(app.server).get('/example.js')
])
expect(res1.statusCode).to.equal(200)
......
......@@ -27,21 +27,9 @@ describe('UI Middleware', function () {
})
it('fetches manifest data', async function () {
const response = await request(app.server).get('/manifests')
expect(response.statusCode).to.equal(200)
expect(response.headers['content-encoding']).to.equal('gzip')
expect(response.body).to.deep.equal([{ namespace: 'test', path: 'example' }])
})
it('fetches manifest data with brotli', async function () {
const response = await request(app.server)
.get('/manifests')
.set('accept-encoding', 'deflate, gzip, br')
.buffer(true)
.parse(brotliParser)
const response = await request(app.server).get('/manifests').parse(brotliParser)
expect(response.statusCode).to.equal(200)
expect(response.headers['content-encoding']).to.equal('br')
expect(response.headers['content-type']).to.equal('application/json; charset=utf-8')
expect(response.body).to.deep.equal([{ namespace: 'test', path: 'example' }])
})
......@@ -56,7 +44,7 @@ describe('UI Middleware', function () {
})
it('caches manifest data', async function () {
const response = await request(app.server).get('/manifests')
const response = await request(app.server).get('/manifests').parse(brotliParser)
expect(response.statusCode).to.equal(200)
expect(response.body).to.deep.equal([{ namespace: 'test', path: 'example' }])
......@@ -67,7 +55,7 @@ describe('UI Middleware', function () {
await new Promise(resolve => setTimeout(resolve, 150))
const response2 = await request(app.server).get('/manifests')
const response2 = await request(app.server).get('/manifests').parse(brotliParser)
expect(response2.statusCode).to.equal(200)
expect(response2.body).to.deep.equal([{ namespace: 'test', path: 'example' }])
})
......@@ -93,6 +81,7 @@ describe('UI Middleware', function () {
it('can load multiple configurations', async function () {
await request(app.server)
.get('/manifests')
.parse(brotliParser)
.then(response => {
expect(response.statusCode).to.equal(200)
expect(response.body).to.deep.equal([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment