Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(client): add tests for buildNFTAnnotations (#11954)
- Loading branch information
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
packages/client/src/__tests__/buildNFTAnnotations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { ClientEngineType } from '@prisma/sdk' | ||
|
||
import { buildNFTAnnotations } from '../generation/utils/buildNFTAnnotations' | ||
|
||
function normalizePaths(snapshot: string): string { | ||
if (process.platform === 'win32') { | ||
return snapshot.replace(/\\\\/g, '/') | ||
} | ||
return snapshot | ||
} | ||
|
||
describe('library', () => { | ||
it('generates annotations for a schema and a single engine', () => { | ||
const annotations = buildNFTAnnotations(ClientEngineType.Library, ['debian-openssl-1.1.x'], 'out') | ||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
path.join(__dirname, "libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node"); | ||
path.join(process.cwd(), "out/libquery_engine-TEST_PLATFORM.so.node") | ||
path.join(__dirname, "schema.prisma"); | ||
path.join(process.cwd(), "out/schema.prisma") | ||
`) | ||
}) | ||
|
||
it('generates annotations for a schema and multiple engines', () => { | ||
const annotations = buildNFTAnnotations( | ||
ClientEngineType.Library, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
) | ||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
path.join(__dirname, "libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node"); | ||
path.join(process.cwd(), "out/libquery_engine-TEST_PLATFORM.so.node") | ||
path.join(__dirname, "libquery_engine-TEST_PLATFORM.dylib.node"); | ||
path.join(process.cwd(), "out/libquery_engine-TEST_PLATFORM.dylib.node") | ||
path.join(__dirname, "query_engine-TEST_PLATFORM.dll.node"); | ||
path.join(process.cwd(), "out/query_engine-TEST_PLATFORM.dll.node") | ||
path.join(__dirname, "schema.prisma"); | ||
path.join(process.cwd(), "out/schema.prisma") | ||
`) | ||
}) | ||
}) | ||
|
||
describe('binary', () => { | ||
it('generates annotations for a schema and a single engine', () => { | ||
const annotations = buildNFTAnnotations(ClientEngineType.Binary, ['debian-openssl-1.1.x'], 'out') | ||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
path.join(__dirname, "query-engine-TEST_PLATFORM"); | ||
path.join(process.cwd(), "out/query-engine-TEST_PLATFORM") | ||
path.join(__dirname, "schema.prisma"); | ||
path.join(process.cwd(), "out/schema.prisma") | ||
`) | ||
}) | ||
|
||
it('generates annotations for a schema and multiple engines', () => { | ||
const annotations = buildNFTAnnotations( | ||
ClientEngineType.Binary, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
) | ||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
path.join(__dirname, "query-engine-TEST_PLATFORM"); | ||
path.join(process.cwd(), "out/query-engine-TEST_PLATFORM") | ||
path.join(__dirname, "query-engine-TEST_PLATFORM"); | ||
path.join(process.cwd(), "out/query-engine-TEST_PLATFORM") | ||
path.join(__dirname, "query-engine-TEST_PLATFORM"); | ||
path.join(process.cwd(), "out/query-engine-TEST_PLATFORM") | ||
path.join(__dirname, "schema.prisma"); | ||
path.join(process.cwd(), "out/schema.prisma") | ||
`) | ||
}) | ||
}) | ||
|
||
describe('dataproxy', () => { | ||
it('generates no annotations', () => { | ||
const annotations = buildNFTAnnotations( | ||
ClientEngineType.DataProxy, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
) | ||
|
||
// TODO: when using .toMatchInlineSnapshot(), this fails after updating snapshots. | ||
// Probably an issue with the snapshot serializer? | ||
expect(normalizePaths(annotations)).toBe(` | ||
`) | ||
}) | ||
}) | ||
|
||
describe('special cases', () => { | ||
/** | ||
* The build image (Debian) is different from the runtime image (RHEL) on Netlify, | ||
* so the build-time targets are replaced with what will actually be required at run time. | ||
*/ | ||
it('replaces platforms with ["rhel-openssl-1.0.x"] on Netlify', () => { | ||
process.env.NETLIFY = 'true' | ||
|
||
const annotations = buildNFTAnnotations( | ||
ClientEngineType.Library, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
) | ||
|
||
delete process.env.NETLIFY | ||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
path.join(__dirname, "libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node"); | ||
path.join(process.cwd(), "out/libquery_engine-TEST_PLATFORM.so.node") | ||
path.join(__dirname, "schema.prisma"); | ||
path.join(process.cwd(), "out/schema.prisma") | ||
`) | ||
|
||
expect(annotations).toContain('rhel-openssl-1.0.x') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters