|
| 1 | +jest.setTimeout(60000); |
| 2 | +process.env.PGPM_SKIP_UPDATE_CHECK = 'true'; |
| 3 | + |
| 4 | +import { PgpmPackage } from '@pgpmjs/core'; |
| 5 | +import * as fs from 'fs'; |
| 6 | +import * as path from 'path'; |
| 7 | + |
| 8 | +import { TestFixture } from '../test-utils'; |
| 9 | + |
| 10 | +describe('cmds:upgrade-modules - with initialized workspace and module', () => { |
| 11 | + let fixture: TestFixture; |
| 12 | + let workspaceDir: string; |
| 13 | + let moduleDir: string; |
| 14 | + |
| 15 | + beforeEach(async () => { |
| 16 | + fixture = new TestFixture(); |
| 17 | + |
| 18 | + const workspaceName = 'my-workspace'; |
| 19 | + const moduleName = 'my-module'; |
| 20 | + workspaceDir = path.join(fixture.tempDir, workspaceName); |
| 21 | + moduleDir = path.join(workspaceDir, 'packages', moduleName); |
| 22 | + |
| 23 | + // Step 1: Create workspace |
| 24 | + await fixture.runCmd({ |
| 25 | + _: ['init', 'workspace'], |
| 26 | + cwd: fixture.tempDir, |
| 27 | + name: workspaceName, |
| 28 | + workspace: true, |
| 29 | + }); |
| 30 | + |
| 31 | + // Step 2: Add module |
| 32 | + await fixture.runCmd({ |
| 33 | + _: ['init'], |
| 34 | + cwd: workspaceDir, |
| 35 | + name: moduleName, |
| 36 | + moduleName: moduleName, |
| 37 | + extensions: ['uuid-ossp', 'plpgsql'], |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + afterEach(() => { |
| 42 | + fixture.cleanup(); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('when no modules are installed', () => { |
| 46 | + it('reports no modules installed', async () => { |
| 47 | + await fixture.runCmd({ |
| 48 | + _: ['upgrade-modules'], |
| 49 | + cwd: moduleDir, |
| 50 | + }); |
| 51 | + |
| 52 | + // Should complete without error |
| 53 | + const mod = new PgpmPackage(moduleDir); |
| 54 | + const result = mod.getInstalledModules(); |
| 55 | + expect(result.installed).toEqual([]); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('when modules are installed at latest version', () => { |
| 60 | + beforeEach(async () => { |
| 61 | + await fixture.runCmd({ |
| 62 | + _: ['install', '@pgpm-testing/[email protected]'], |
| 63 | + cwd: moduleDir, |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('reports modules are up to date', async () => { |
| 68 | + await fixture.runCmd({ |
| 69 | + _: ['upgrade-modules'], |
| 70 | + cwd: moduleDir, |
| 71 | + all: true, |
| 72 | + }); |
| 73 | + |
| 74 | + const pkgJson = JSON.parse( |
| 75 | + fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8') |
| 76 | + ); |
| 77 | + expect(pkgJson.dependencies['@pgpm-testing/base32']).toBe('1.2.0'); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + describe('when modules need upgrading (1.1.0 -> 1.2.0)', () => { |
| 82 | + beforeEach(async () => { |
| 83 | + await fixture.runCmd({ |
| 84 | + _: ['install', '@pgpm-testing/[email protected]'], |
| 85 | + cwd: moduleDir, |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it('dry run does not modify package.json', async () => { |
| 90 | + await fixture.runCmd({ |
| 91 | + _: ['upgrade-modules'], |
| 92 | + cwd: moduleDir, |
| 93 | + 'dry-run': true, |
| 94 | + }); |
| 95 | + |
| 96 | + const pkgJson = JSON.parse( |
| 97 | + fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8') |
| 98 | + ); |
| 99 | + expect(pkgJson.dependencies['@pgpm-testing/base32']).toBe('1.1.0'); |
| 100 | + }); |
| 101 | + |
| 102 | + it('--all flag upgrades from 1.1.0 to 1.2.0', async () => { |
| 103 | + let pkgJson = JSON.parse( |
| 104 | + fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8') |
| 105 | + ); |
| 106 | + expect(pkgJson.dependencies['@pgpm-testing/base32']).toBe('1.1.0'); |
| 107 | + |
| 108 | + await fixture.runCmd({ |
| 109 | + _: ['upgrade-modules'], |
| 110 | + cwd: moduleDir, |
| 111 | + all: true, |
| 112 | + }); |
| 113 | + |
| 114 | + pkgJson = JSON.parse( |
| 115 | + fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8') |
| 116 | + ); |
| 117 | + expect(pkgJson.dependencies['@pgpm-testing/base32']).toBe('1.2.0'); |
| 118 | + }); |
| 119 | + |
| 120 | + it('--modules flag filters to specific modules', async () => { |
| 121 | + let pkgJson = JSON.parse( |
| 122 | + fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8') |
| 123 | + ); |
| 124 | + expect(pkgJson.dependencies['@pgpm-testing/base32']).toBe('1.1.0'); |
| 125 | + |
| 126 | + await fixture.runCmd({ |
| 127 | + _: ['upgrade-modules'], |
| 128 | + cwd: moduleDir, |
| 129 | + modules: '@pgpm-testing/base32', |
| 130 | + all: true, |
| 131 | + }); |
| 132 | + |
| 133 | + pkgJson = JSON.parse( |
| 134 | + fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8') |
| 135 | + ); |
| 136 | + expect(pkgJson.dependencies['@pgpm-testing/base32']).toBe('1.2.0'); |
| 137 | + }); |
| 138 | + }); |
| 139 | +}); |
0 commit comments