|
| 1 | +import { mkdir, readFile, rmdir, writeFile } from 'node:fs/promises' |
| 2 | +import { join } from 'node:path' |
| 3 | +import { cwd } from 'node:process' |
| 4 | +import { afterEach, beforeEach, expect, it } from 'vitest' |
| 5 | +import { Operation } from '../src/operation' |
| 6 | +import { updateFiles } from '../src/update-files' |
| 7 | + |
| 8 | +beforeEach(async () => { |
| 9 | + mkdir(join(cwd(), 'test', 'update-files', 'testdata'), { recursive: true }).catch(() => { }) |
| 10 | +}) |
| 11 | + |
| 12 | +afterEach(async () => { |
| 13 | + rmdir(join(cwd(), 'test', 'update-files', 'testdata'), { recursive: true }).catch(() => { }) |
| 14 | +}) |
| 15 | + |
| 16 | +it('should skip to modify the manifest file if version field is not specified', async () => { |
| 17 | + await writeFile(join(cwd(), 'test', 'update-files', 'testdata', 'package.json'), JSON.stringify({}), 'utf8') |
| 18 | + |
| 19 | + const operation = await Operation.start({ |
| 20 | + cwd: join(cwd(), 'test', 'update-files', 'testdata'), |
| 21 | + currentVersion: '1.0.0', |
| 22 | + }) |
| 23 | + |
| 24 | + operation.update({ |
| 25 | + newVersion: '2.0.0', |
| 26 | + }) |
| 27 | + |
| 28 | + await updateFiles(operation) |
| 29 | + const updatedPackageJSON = await readFile(join(cwd(), 'test', 'update-files', 'testdata', 'package.json'), 'utf8') |
| 30 | + expect(JSON.parse(updatedPackageJSON)).toMatchObject({}) |
| 31 | +}) |
0 commit comments