mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
test: fix and run tests on Windows (#11257)
* Skip tests that don't work on Windows * Bring back tests on Windows * Skip the test on all platforms exept Windows * Make the test run only on Windows * Add simple winodws test * fix cli test on Windows * let's see if this test passes on linux * limit test to Windows and run format * Add withPlatform test helper * Mock platform in file path tests using withPlatform() * Fix test: relative paths should not change on non-win32 platforms * Lowercase relative path on non-win32 platform * test: add better-sqlite3 and sqlite for Windows tests --------- Co-authored-by: Simon Garner <simon@equalogic.com>
This commit is contained in:
parent
ae96f87923
commit
5d6d893662
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@ -48,8 +48,11 @@ jobs:
|
||||
with:
|
||||
node-version: ${{matrix.node-version}}
|
||||
|
||||
windows-database-tests:
|
||||
uses: ./.github/workflows/windows-database-tests.yml
|
||||
|
||||
# Run with most databases possible to provide the coverage of the tests
|
||||
coverage:
|
||||
if: ${{ always() }}
|
||||
needs: [database-tests, database-compose-tests]
|
||||
needs: [database-tests, database-compose-tests, windows-database-tests]
|
||||
uses: ./.github/workflows/coverage.yml
|
||||
|
||||
49
.github/workflows/windows-database-tests.yml
vendored
Normal file
49
.github/workflows/windows-database-tests.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
name: database-tests
|
||||
|
||||
on: workflow_call
|
||||
|
||||
jobs:
|
||||
|
||||
better-sqlite3:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: npm i
|
||||
- run: cp .github/workflows/test/better-sqlite3.ormconfig.json ormconfig.json
|
||||
- run: npx nyc npm run test
|
||||
- name: Coveralls Parallel
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
flag-name: better-sqlite3-windows
|
||||
parallel: true
|
||||
|
||||
|
||||
sqlite:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: npm i
|
||||
- run: cp .github/workflows/test/sqlite.ormconfig.json ormconfig.json
|
||||
- run: npx nyc npm run test
|
||||
- name: Coveralls Parallel
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
flag-name: sqlite-windows
|
||||
parallel: true
|
||||
|
||||
|
||||
sqljs:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: npm i
|
||||
- run: cp .github/workflows/test/sqljs.ormconfig.json ormconfig.json
|
||||
- run: npx nyc npm run test
|
||||
- name: Coveralls Parallel
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
flag-name: sqljs-windows
|
||||
parallel: true
|
||||
@ -5,6 +5,7 @@ import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
withPlatform,
|
||||
} from "../../../utils/test-utils"
|
||||
import { Answer } from "./entity/Answer"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -21,37 +22,27 @@ const VALID_NAME_REGEX = /^(?!sqlite_).{1,63}$/
|
||||
describe("multi-database > basic-functionality", () => {
|
||||
describe("filepathToName()", () => {
|
||||
for (const platform of [`darwin`, `win32`]) {
|
||||
let realPlatform: string
|
||||
|
||||
beforeEach(() => {
|
||||
realPlatform = process.platform
|
||||
Object.defineProperty(process, `platform`, {
|
||||
configurable: true,
|
||||
value: platform,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, `platform`, {
|
||||
configurable: true,
|
||||
value: realPlatform,
|
||||
})
|
||||
})
|
||||
|
||||
it(`produces deterministic, unique, and valid table names for relative paths; leaves absolute paths unchanged (${platform})`, () => {
|
||||
it(`[${platform}] produces deterministic, unique, and valid table names for relative paths; leaves absolute paths unchanged`, () => {
|
||||
const testMap = [
|
||||
["FILENAME.db", "filename.db"],
|
||||
["..\\FILENAME.db", "../filename.db"],
|
||||
["..\\FILENAME.db", platform === 'win32' ? "../filename.db" : "..\\filename.db"],
|
||||
[".\\FILENAME.db", platform === 'win32' ? "./filename.db" : ".\\filename.db"],
|
||||
[
|
||||
"..\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\FILENAME.db",
|
||||
"../longpathdir/longpathdir/longpathdir/longpathdir/longpathdir/longpathdir/longpathdir/filename.db",
|
||||
platform === 'win32'
|
||||
? "../longpathdir/longpathdir/longpathdir/longpathdir/longpathdir/longpathdir/longpathdir/filename.db"
|
||||
: "..\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\longpathdir\\filename.db",
|
||||
],
|
||||
["C:\\dirFILENAME.db", "C:\\dirFILENAME.db"],
|
||||
["/dir/filename.db", "/dir/filename.db"],
|
||||
]
|
||||
for (const [winOs, otherOs] of testMap) {
|
||||
const winOsRes = filepathToName(winOs)
|
||||
const otherOsRes = filepathToName(otherOs)
|
||||
const winOsRes = withPlatform(platform, () =>
|
||||
filepathToName(winOs),
|
||||
)
|
||||
const otherOsRes = withPlatform(platform, () =>
|
||||
filepathToName(otherOs),
|
||||
)
|
||||
expect(winOsRes).to.equal(otherOsRes)
|
||||
expect(winOsRes).to.match(
|
||||
VALID_NAME_REGEX,
|
||||
@ -91,7 +82,7 @@ describe("multi-database > basic-functionality", () => {
|
||||
beforeEach(() => reloadTestingDatabases(connections))
|
||||
after(async () => {
|
||||
await closeTestingConnections(connections)
|
||||
await rimraf(`${tempPath}/**/*.attach.db`)
|
||||
await rimraf(`${tempPath}/**/*.attach.db`, { glob: true })
|
||||
})
|
||||
|
||||
it("should correctly attach and create database files", () =>
|
||||
|
||||
@ -52,7 +52,7 @@ describe("cli init command", () => {
|
||||
for (const databaseOption of databaseOptions) {
|
||||
it(`should work with ${databaseOption} option`, (done) => {
|
||||
exec(
|
||||
`${cliPath} init --name ${testProjectName} --database ${databaseOption}`,
|
||||
`node ${cliPath} init --name ${testProjectName} --database ${databaseOption}`,
|
||||
(error, stdout, stderr) => {
|
||||
if (error) console.log(error)
|
||||
expect(error).to.not.exist
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { isAbsolute, toPortablePath } from "../../src/util/PathUtils"
|
||||
import { expect } from "chai"
|
||||
import { withPlatform } from "../utils/test-utils"
|
||||
|
||||
describe(`path-utils`, () => {
|
||||
describe("isAbsolute", () => {
|
||||
@ -26,139 +27,148 @@ describe(`path-utils`, () => {
|
||||
|
||||
describe("toPortablePath", () => {
|
||||
for (const platform of [`darwin`, `win32`]) {
|
||||
let realPlatform: string
|
||||
|
||||
describe(`Platform ${platform}`, () => {
|
||||
beforeEach(() => {
|
||||
realPlatform = process.platform
|
||||
Object.defineProperty(process, `platform`, {
|
||||
configurable: true,
|
||||
value: platform,
|
||||
describe(`[${platform}] toPortablePath`, () => {
|
||||
if (platform !== `win32`) {
|
||||
it(`shouldn't change paths on non-Windows platform`, () => {
|
||||
const inputPath = `C:\\Users\\user\\proj`
|
||||
const outputPath = inputPath
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, `platform`, {
|
||||
configurable: true,
|
||||
value: realPlatform,
|
||||
} else {
|
||||
it(`shouldn't change absolute posix paths when producing portable path`, () => {
|
||||
const inputPath = `/home/user/proj`
|
||||
const outputPath = inputPath
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
})
|
||||
|
||||
describe(`toPortablePath`, () => {
|
||||
if (platform !== `win32`) {
|
||||
it(`should change paths on non-Windows platform`, () => {
|
||||
const inputPath = `C:\\Users\\user\\proj`
|
||||
const outputPath = inputPath
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
} else {
|
||||
it(`shouldn't change absolute posix paths when producing portable path`, () => {
|
||||
const inputPath = `/home/user/proj`
|
||||
const outputPath = inputPath
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`shouldn't change absolute paths that are already portable`, () => {
|
||||
const inputPath = `/c:/Users/user/proj`
|
||||
const outputPath = `/c:/Users/user/proj`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`shouldn't change absolute paths that are already portable`, () => {
|
||||
const inputPath = `/c:/Users/user/proj`
|
||||
const outputPath = `/c:/Users/user/proj`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should normalize the slashes in relative Windows paths`, () => {
|
||||
const inputPath = `..\\Users\\user/proj`
|
||||
const outputPath = `../Users/user/proj`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should normalize the slashes in relative Windows paths`, () => {
|
||||
const inputPath = `..\\Users\\user/proj`
|
||||
const outputPath = `../Users/user/proj`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should transform Windows paths into their posix counterparts (uppercase drive)`, () => {
|
||||
const inputPath = `C:\\Users\\user\\proj`
|
||||
const outputPath = `/C:/Users/user/proj`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should transform Windows paths into their posix counterparts (uppercase drive)`, () => {
|
||||
const inputPath = `C:\\Users\\user\\proj`
|
||||
const outputPath = `/C:/Users/user/proj`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should transform Windows paths into their posix counterparts (lowercase drive)`, () => {
|
||||
const inputPath = `c:\\Users\\user\\proj`
|
||||
const outputPath = `/c:/Users/user/proj`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should transform Windows paths into their posix counterparts (lowercase drive)`, () => {
|
||||
const inputPath = `c:\\Users\\user\\proj`
|
||||
const outputPath = `/c:/Users/user/proj`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should transform Windows paths into their posix counterparts (forward slashes)`, () => {
|
||||
const inputPath = `C:/Users/user/proj`
|
||||
const outputPath = `/C:/Users/user/proj`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should transform Windows paths into their posix counterparts (forward slashes)`, () => {
|
||||
const inputPath = `C:/Users/user/proj`
|
||||
const outputPath = `/C:/Users/user/proj`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should support Windows paths that contain both backslashes and forward slashes`, () => {
|
||||
const inputPath = `C:/Users\\user/proj`
|
||||
const outputPath = `/C:/Users/user/proj`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should support Windows paths that contain both backslashes and forward slashes`, () => {
|
||||
const inputPath = `C:/Users\\user/proj`
|
||||
const outputPath = `/C:/Users/user/proj`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should support drive: Windows paths`, () => {
|
||||
const inputPath = `C:`
|
||||
const outputPath = `/C:`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should support drive: Windows paths`, () => {
|
||||
const inputPath = `C:`
|
||||
const outputPath = `/C:`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should support UNC Windows paths (\\\\[server]\\[sharename]\\)`, () => {
|
||||
const inputPath = `\\\\Server01\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/Server01/user/docs/Letter.txt`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should support UNC Windows paths (\\\\[server]\\[sharename]\\)`, () => {
|
||||
const inputPath = `\\\\Server01\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/Server01/user/docs/Letter.txt`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should support Long UNC Windows paths (\\\\?\\[server]\\[sharename]\\)`, () => {
|
||||
const inputPath = `\\\\?\\Server01\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/?/Server01/user/docs/Letter.txt`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should support Long UNC Windows paths (\\\\?\\[server]\\[sharename]\\)`, () => {
|
||||
const inputPath = `\\\\?\\Server01\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/?/Server01/user/docs/Letter.txt`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should support Long UNC Windows paths (\\\\?\\UNC\\[server]\\[sharename]\\)`, () => {
|
||||
const inputPath = `\\\\?\\UNC\\Server01\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/?/UNC/Server01/user/docs/Letter.txt`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should support Long UNC Windows paths (\\\\?\\UNC\\[server]\\[sharename]\\)`, () => {
|
||||
const inputPath = `\\\\?\\UNC\\Server01\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/?/UNC/Server01/user/docs/Letter.txt`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
it(`should support Long UNC Windows paths (\\\\?\\[drive_spec]:\\)`, () => {
|
||||
const inputPath = `\\\\?\\C:\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/?/C:/user/docs/Letter.txt`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
|
||||
it(`should support Long UNC Windows paths (\\\\?\\[drive_spec]:\\)`, () => {
|
||||
const inputPath = `\\\\?\\C:\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/?/C:/user/docs/Letter.txt`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
|
||||
it(`should support Long UNC Windows paths with dot (\\\\.\\[physical_device]\\)`, () => {
|
||||
const inputPath = `\\\\.\\PhysicalDevice\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/.dot/PhysicalDevice/user/docs/Letter.txt`
|
||||
expect(toPortablePath(inputPath)).to.equal(
|
||||
outputPath,
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
it(`should support Long UNC Windows paths with dot (\\\\.\\[physical_device]\\)`, () => {
|
||||
const inputPath = `\\\\.\\PhysicalDevice\\user\\docs\\Letter.txt`
|
||||
const outputPath = `/unc/.dot/PhysicalDevice/user/docs/Letter.txt`
|
||||
expect(
|
||||
withPlatform(platform, () =>
|
||||
toPortablePath(inputPath),
|
||||
),
|
||||
).to.equal(outputPath)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@ -591,3 +591,21 @@ export async function createTypeormMetadataTable(
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
export function withPlatform<R>(platform: string, fn: () => R): R {
|
||||
const realPlatform = process.platform
|
||||
|
||||
Object.defineProperty(process, `platform`, {
|
||||
configurable: true,
|
||||
value: platform,
|
||||
})
|
||||
|
||||
const result = fn()
|
||||
|
||||
Object.defineProperty(process, `platform`, {
|
||||
configurable: true,
|
||||
value: realPlatform,
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user