From d9d30d6fa27655d40194a87591c6bc369999b070 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 30 Apr 2022 16:40:13 +0300 Subject: [PATCH] test: improve tests that init a git repo --- .../filter-workspace-packages/test/index.ts | 2 +- .../test/__fixtures__/simple/pnpm-lock.yaml | 13 +++++------ .../test/gitChecks.ts | 9 ++++---- .../test/publish.ts | 3 +-- packages/pnpm/test/monorepo/index.ts | 12 +++++----- .../test/fixture/project/pnpm-lock.yaml | 22 ++++++++++--------- privatePackages/test-fixtures/package.json | 2 +- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/packages/filter-workspace-packages/test/index.ts b/packages/filter-workspace-packages/test/index.ts index 799d5d1431..9fa9635285 100644 --- a/packages/filter-workspace-packages/test/index.ts +++ b/packages/filter-workspace-packages/test/index.ts @@ -347,7 +347,7 @@ test('select changed packages', async () => { } const workspaceDir = tempy.directory() - await execa('git', ['init'], { cwd: workspaceDir }) + await execa('git', ['init', '--initial-branch=main'], { cwd: workspaceDir }) await execa('git', ['config', 'user.email', 'x@y.z'], { cwd: workspaceDir }) await execa('git', ['config', 'user.name', 'xyz'], { cwd: workspaceDir }) await execa('git', ['commit', '--allow-empty', '--allow-empty-message', '-m', '', '--no-gpg-sign'], { cwd: workspaceDir }) diff --git a/packages/mount-modules/test/__fixtures__/simple/pnpm-lock.yaml b/packages/mount-modules/test/__fixtures__/simple/pnpm-lock.yaml index 244abfbeb9..4dbefca975 100644 --- a/packages/mount-modules/test/__fixtures__/simple/pnpm-lock.yaml +++ b/packages/mount-modules/test/__fixtures__/simple/pnpm-lock.yaml @@ -1,14 +1,14 @@ +lockfileVersion: 5.4 + importers: .: - dependencies: - '@zkochan/git-config': 0.1.0 - is-positive: 1.0.0 specifiers: '@zkochan/git-config': 0.1.0 is-positive: 1.0.0 - -lockfileVersion: 5.3 + dependencies: + '@zkochan/git-config': 0.1.0 + is-positive: 1.0.0 packages: @@ -24,6 +24,5 @@ packages: /is-positive/1.0.0: resolution: {integrity: sha1-iACYVrZKLx632LsBeUGEJK4EUss=} + engines: {node: '>=0.10.0'} dev: false - engines: - node: '>=0.10.0' diff --git a/packages/plugin-commands-publishing/test/gitChecks.ts b/packages/plugin-commands-publishing/test/gitChecks.ts index 3ae5be0be4..c5b0678c01 100644 --- a/packages/plugin-commands-publishing/test/gitChecks.ts +++ b/packages/plugin-commands-publishing/test/gitChecks.ts @@ -30,8 +30,7 @@ test('publish: fails git check if branch is not on master or main', async () => version: '0.0.0', }) - await execa('git', ['init']) - await execa('git', ['checkout', '-b', 'test']) + await execa('git', ['init', '--initial-branch=test']) await execa('git', ['config', 'user.email', 'x@y.z']) await execa('git', ['config', 'user.name', 'xyz']) await execa('git', ['add', '*']) @@ -87,7 +86,7 @@ test('publish: fails git check if branch is not clean', async () => { version: '0.0.0', }) - await execa('git', ['init']) + await execa('git', ['init', '--initial-branch=main']) await execa('git', ['config', 'user.email', 'x@y.z']) await execa('git', ['config', 'user.name', 'xyz']) await execa('git', ['add', '*']) @@ -114,7 +113,7 @@ test('publish: fails git check if branch is not up-to-date', async () => { version: '0.0.0', }) - await execa('git', ['init']) + await execa('git', ['init', '--initial-branch=main']) await execa('git', ['config', 'user.email', 'x@y.z']) await execa('git', ['config', 'user.name', 'xyz']) await execa('git', ['init', '--bare'], { cwd: remote }) @@ -122,7 +121,7 @@ test('publish: fails git check if branch is not up-to-date', async () => { await execa('git', ['commit', '-m', 'init', '--no-gpg-sign']) await execa('git', ['commit', '--allow-empty', '--allow-empty-message', '-m', '', '--no-gpg-sign']) await execa('git', ['remote', 'add', 'origin', remote]) - await execa('git', ['push', '-u', 'origin', 'master']) + await execa('git', ['push', '-u', 'origin', 'main']) await execa('git', ['reset', '--hard', 'HEAD~1']) await expect( diff --git a/packages/plugin-commands-publishing/test/publish.ts b/packages/plugin-commands-publishing/test/publish.ts index c7249c0ddb..8750fe18b5 100644 --- a/packages/plugin-commands-publishing/test/publish.ts +++ b/packages/plugin-commands-publishing/test/publish.ts @@ -693,8 +693,7 @@ test('publish: with specified publish branch name', async () => { }) const branch = 'some-random-publish-branch' - await execa('git', ['init']) - await execa('git', ['checkout', '-b', branch]) + await execa('git', ['init', '--initial-branch=branch']) await execa('git', ['config', 'user.email', 'x@y.z']) await execa('git', ['config', 'user.name', 'xyz']) await execa('git', ['add', '*']) diff --git a/packages/pnpm/test/monorepo/index.ts b/packages/pnpm/test/monorepo/index.ts index d67eda4eb6..18d0f53517 100644 --- a/packages/pnpm/test/monorepo/index.ts +++ b/packages/pnpm/test/monorepo/index.ts @@ -326,14 +326,14 @@ test('test-pattern is respected by the test script', async () => { }, ]) - await execa('git', ['init']) + await execa('git', ['init', '--initial-branch=main']) await execa('git', ['config', 'user.email', 'x@y.z']) await execa('git', ['config', 'user.name', 'xyz']) await execa('git', ['init', '--bare'], { cwd: remote }) await execa('git', ['add', '*']) await execa('git', ['commit', '-m', 'init', '--no-gpg-sign']) await execa('git', ['remote', 'add', 'origin', remote]) - await execa('git', ['push', '-u', 'origin', 'master']) + await execa('git', ['push', '-u', 'origin', 'main']) await fs.writeFile('project-2/file.js', '') await fs.writeFile('project-4/different-pattern.js', '') @@ -347,7 +347,7 @@ test('test-pattern is respected by the test script', async () => { await execPnpm(['install']) - await execPnpm(['recursive', 'test', '--filter', '...[origin/master]']) + await execPnpm(['recursive', 'test', '--filter', '...[origin/main]']) const { default: output } = await import(path.resolve('..', 'output.json')) expect(output.sort()).toStrictEqual(['project-2', 'project-4']) @@ -379,14 +379,14 @@ test('changed-files-ignore-pattern is respected', async () => { }, ]) - await execa('git', ['init']) + await execa('git', ['init', '--initial-branch=main']) await execa('git', ['config', 'user.email', 'x@y.z']) await execa('git', ['config', 'user.name', 'xyz']) await execa('git', ['init', '--bare'], { cwd: remote }) await execa('git', ['add', '*']) await execa('git', ['commit', '-m', 'init', '--no-gpg-sign']) await execa('git', ['remote', 'add', 'origin', remote]) - await execa('git', ['push', '-u', 'origin', 'master']) + await execa('git', ['push', '-u', 'origin', 'main']) const npmrcLines = [] await fs.writeFile('project-2-change-is-never-ignored/index.js', '') @@ -427,7 +427,7 @@ test('changed-files-ignore-pattern is respected', async () => { const result = await execPnpmSync( [ '--filter', - '[origin/master]', + '[origin/main]', opts?.overrideChangedFilesIgnorePatternWithNoPattern ? '--changed-files-ignore-pattern=' : '', diff --git a/privatePackages/assert-store/test/fixture/project/pnpm-lock.yaml b/privatePackages/assert-store/test/fixture/project/pnpm-lock.yaml index c08ac6c5c5..b572ed584a 100644 --- a/privatePackages/assert-store/test/fixture/project/pnpm-lock.yaml +++ b/privatePackages/assert-store/test/fixture/project/pnpm-lock.yaml @@ -1,12 +1,14 @@ -dependencies: - is-positive: 3.1.0 -lockfileVersion: 5.2 -packages: - /is-positive/3.1.0: - dev: false - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-hX21hKG6XRyymAUn/DtsQ103sP0= +lockfileVersion: 5.4 + specifiers: is-positive: 3.1.0 + +dependencies: + is-positive: 3.1.0 + +packages: + + /is-positive/3.1.0: + resolution: {integrity: sha1-hX21hKG6XRyymAUn/DtsQ103sP0=} + engines: {node: '>=0.10.0'} + dev: false diff --git a/privatePackages/test-fixtures/package.json b/privatePackages/test-fixtures/package.json index acd9ee3ae7..2180b091bf 100644 --- a/privatePackages/test-fixtures/package.json +++ b/privatePackages/test-fixtures/package.json @@ -29,7 +29,7 @@ "scripts": { "lint": "tslint -c ../../tslint.json --project .", "compile": "rimraf tsconfig.tsbuildinfo lib && tsc --build", - "test": "pnpm run tsc" + "test": "pnpm run compile" }, "dependencies": { "@pnpm/prepare": "workspace:*",