Skip to content

Commit

Permalink
test: add @types/node into esm test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rostislav-simonik committed Dec 9, 2024
1 parent fb88f52 commit 1f7c869
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/__helpers__/nodeVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Semver from 'semver'

export const getNodeMajorVersion = () => {
const parsedNodeVersion = Semver.parse(process.version)
if (!parsedNodeVersion) {
throw new Error(`Failed to parse node version: ${process.version}`)
}
return parsedNodeVersion.major
}
20 changes: 19 additions & 1 deletion tests/__providers__/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { merge } from 'lodash'
import readPkgUp from 'read-pkg-up'
import { PackageJson, TsConfigJson } from 'type-fest'
import { assertBuildPresent } from '../__helpers__/helpers'
import { getNodeMajorVersion } from '../__helpers__/nodeVersion'
import { getDynamicPackagesVersions } from '../__helpers__/packagesVersions'
import type * as Run from './run'

Expand All @@ -14,6 +15,7 @@ type Project = {
}
packageJson: {
mergeAsync(fields: PackageJson): Promise<void>
mergeIfExistAsync(fields: PackageJson): Promise<void>
createAsync(fields: PackageJson): Promise<void>
}
tsconfig: {
Expand Down Expand Up @@ -52,9 +54,10 @@ export const project = () =>
await ctx.fs.copyAsync(path, ctx.fs.cwd(), {
overwrite: true,
})
await api.packageJson.mergeAsync({
await api.packageJson.mergeIfExistAsync({
devDependencies: {
'@prisma/client': dynamicPackagesVersions['@prisma/client'],
'@types/node': `^${getNodeMajorVersion()}.0.0`,
prisma: dynamicPackagesVersions.prisma,
graphql: dynamicPackagesVersions.graphql,
nexus: dynamicPackagesVersions.nexus,
Expand All @@ -73,6 +76,21 @@ export const project = () =>
const PackageJsonNew = merge(PackageJson, fields)
await ctx.fs.writeAsync(fileName, PackageJsonNew, { jsonIndent: 2 })
},
mergeIfExistAsync: async (fields) => {
const fileName = 'package.json'
const PackageJson = await ctx.fs.readAsync(fileName, 'json')
const PackageJsonNew = Object.assign({}, PackageJson)
Object.keys(fields).forEach((key) => {
const destinationField = (PackageJsonNew[key] ??= {})
const sourceField = fields[key] as Record<string, string>
Object.keys(sourceField).forEach((subKey) => {
if (destinationField[subKey] != null) {
destinationField[subKey] = sourceField[subKey]
}
})
})
await ctx.fs.writeAsync(fileName, PackageJsonNew, { jsonIndent: 2 })
},
},
tsconfig: {
createAsync: async (tsconfig) => {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/fixtures/esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"devDependencies": {
"@prisma/client": "__dynamic__",
"@types/node": "__dynamic__",
"graphql": "__dynamic__",
"nexus": "__dynamic__",
"prisma": "__dynamic__",
Expand Down

0 comments on commit 1f7c869

Please sign in to comment.