test: cli init with local typeorm package (#9926)

* test: cli init with local typeorm package

Uses the locally built files instead of the typeorm
package published to npmjs. This enables testing project
initialisation with unreleased typeorm package versions.

* fix: enable init cli to be testable w non-releases
This commit is contained in:
mptr 2023-04-13 02:24:44 +02:00 committed by GitHub
parent 4240258b50
commit 3a72e35081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

2
.gitignore vendored
View File

@ -9,6 +9,8 @@ node_modules/
ormlogs.log
npm-debug.log
/test/github-issues/799/tmp/*
# test projects generated by test/github-issues/issue-8975.ts
/*TestProject
# ignore yarn2 artifacts but allow yarn.lock (forces yarn1 compat which is node_modules)
.yarn/
.yarn*

View File

@ -695,7 +695,10 @@ Steps to run this project:
if (!packageJson.dependencies) packageJson.dependencies = {}
Object.assign(packageJson.dependencies, {
typeorm: require("../package.json").version,
typeorm:
require("../package.json").version !== "0.0.0"
? require("../package.json").version // install version from package.json if present
: require("../package.json").installFrom, // else use custom source
"reflect-metadata": "^0.1.13",
})

View File

@ -1,5 +1,6 @@
import { expect } from "chai"
import { exec } from "child_process"
import { readFileSync, writeFileSync } from "fs"
import { dirname } from "path"
import rimraf from "rimraf"
@ -29,16 +30,19 @@ describe("cli init command", () => {
})
})
const copyPromise = new Promise<void>((resolve) => {
exec(
`cp package.json ${builtSrcDirectory}`,
(error, stdout, stderr) => {
expect(error).to.not.exist
expect(stderr).to.be.empty
resolve()
},
const copyPromise = new Promise<void>(async (resolve) => {
// load package.json from the root of the project
const packageJson = JSON.parse(
readFileSync("./package.json", "utf8"),
)
packageJson.version = `0.0.0` // install no version but
packageJson.installFrom = `file:../${builtSrcDirectory}` // use the built src directory
// write the modified package.json to the build directory
writeFileSync(
`./${builtSrcDirectory}/package.json`,
JSON.stringify(packageJson, null, 4),
)
resolve()
})
await Promise.all([chmodPromise, copyPromise])
@ -57,6 +61,7 @@ describe("cli init command", () => {
exec(
`${cliPath} init --name ${testProjectName} --database ${databaseOption}`,
(error, stdout, stderr) => {
if (error) console.log(error)
expect(error).to.not.exist
expect(stderr).to.be.empty