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

Fix: The hashed version of the vite manifests does not change

Root cause: Hash was computed on array.toString() which does not change much.
Solution: Use the actual content of the vite manifests to compute the version.
parent 88a06a2e
No related branches found
No related tags found
No related merge requests found
......@@ -52,7 +52,7 @@ describe('Responses contain custom headers', () => {
it('index.html has version', async () => {
const response = await request(app).get('/index.html')
expect(response.statusCode).toBe(200)
expect(response.headers.version).toMatch(/\d*\.3220550168/)
expect(response.headers.version).toMatch(/\d*\.\d*/)
})
it('javascript file contains dependencies', async () => {
......
import { describe, it, expect } from '@jest/globals'
import { hash } from '../src/util'
import { generateSimpleViteManifest } from './util'
describe('Util', function () {
describe('hash function', function () {
it('computes the hash', function () {
const manifest = generateSimpleViteManifest({
'example.js': { imports: ['test.css'] },
'test.css': { }
})
expect(hash(manifest)).toEqual('2245696177')
})
it('the hash changes when the manifest changes', function () {
const manifest = generateSimpleViteManifest({
'example.js': { imports: ['test.css'] },
'test.css': { }
})
const manifestChanged = generateSimpleViteManifest({
'example.js': { imports: ['test1.css'] },
'test1.css': { }
})
expect(hash(manifest)).not.toEqual(hash(manifestChanged))
expect(hash(manifest)).toEqual('2245696177')
expect(hash(manifestChanged)).toEqual('2547998666')
})
})
})
// totaly awesome hash function. Do not use this for encryption (crypto.subtle.digest etc would be overkill for this)
export function hash (array) {
const string = array.toString()
const string = JSON.stringify(array)
if (!string.length) throw new Error('TypeError: Unexpected data to calculate hash from')
let hash = 0
......
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