Skip to content

Commit

Permalink
[service] work around node issue nodejs/node#48886 that causes tests …
Browse files Browse the repository at this point in the history
…to fail using deep equals assertion on url objects
  • Loading branch information
restjohn committed Aug 28, 2023
1 parent 0fcdb25 commit 091d559
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion service/src/adapters/icons/adapters.icons.db.mongoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class MongooseStaticIconRepository extends BaseMongooseRepository<StaticI
}

async loadContent(id: StaticIconId): Promise<[StaticIcon, NodeJS.ReadableStream] | null | UrlResolutionError> {
let icon = await this.model.findById(id)
const icon = await this.model.findById(id)
if (!icon) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL } from 'url'
import { expect } from 'chai'
import _, { uniq, uniqueId } from 'lodash'
import _ from 'lodash'
import { MongoMemoryServer } from 'mongodb-memory-server'
import mongoose from 'mongoose'
import uniqid from 'uniqid'
Expand All @@ -10,6 +10,7 @@ import { MongooseStaticIconRepository, StaticIconDocument, StaticIconModel } fro
import { EntityIdFactory, UrlResolutionError, UrlScheme } from '../../../lib/entities/entities.global'
import { Readable } from 'stream'


interface TestUrlScheme extends UrlScheme {
urlWithPath(path: string): URL
}
Expand Down Expand Up @@ -130,7 +131,6 @@ describe('static icon mongoose repository', function() {
it('replaces icon properties for an existing source url when the content hash changes', async function() {

const sourceUrl = new URL('mage:///test/replace.png')

const origAttrs: Required<StaticIconStub> = {
sourceUrl,
imageType: 'raster',
Expand All @@ -145,7 +145,7 @@ describe('static icon mongoose repository', function() {
summary: 'replace me'
}
const updatedAttrs: Required<StaticIconStub> = {
sourceUrl,
sourceUrl: new URL(sourceUrl.toString()),
imageType: 'vector',
sizeBytes: 1100,
sizePixels: { width: 220, height: 220 },
Expand Down Expand Up @@ -688,7 +688,7 @@ describe('static icon mongoose repository', function() {
tags: []
}
scheme2LocalIcon = {
id: uniqueId(),
id: uniqid(),
sourceUrl: scheme2Local.urlWithPath('test2.png'),
registeredTimestamp: Date.now(),
resolvedTimestamp: Date.now(),
Expand Down
1 change: 0 additions & 1 deletion service/test/app/systemInfo/app.systemInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const mockEnvironmentInfo: EnvironmentInfo = {
const mockDisclaimer = {};
const mockContactInfo = {};

// Test utility function
function requestBy<T extends object>(
principal: string,
params?: T
Expand Down
15 changes: 14 additions & 1 deletion service/test/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@


import url from 'url'

/**
* This class works around issue https://github.com/nodejs/node/issues/48886,
* which was introduced in Node 18.17.0.
*/
url.URL = class Node_18_17_Issue_48886_URL extends url.URL {
constructor(input: string, base?: string | url.URL) {
super(input, base)
this.searchParams
}
}

declare module 'mocha' {
namespace Mocha {
interface MochaOptions {}
}
}


import chai, { Assertion } from 'chai'
import asPromised from 'chai-as-promised'

Expand Down

0 comments on commit 091d559

Please sign in to comment.