|
| 1 | +/** |
| 2 | + * @file Functional Tests - toggle |
| 3 | + * @module toggle-pkg-type/tests/toggle/functional |
| 4 | + */ |
| 5 | + |
| 6 | +import vfs from '#fixtures/volume' |
| 7 | +import type { PackageJson } from 'type-fest' |
| 8 | +import testSubject from '../toggle' |
| 9 | + |
| 10 | +vi.mock('node:fs') |
| 11 | + |
| 12 | +describe('functional:toggle', () => { |
| 13 | + afterEach(() => { |
| 14 | + vfs.reset() |
| 15 | + }) |
| 16 | + |
| 17 | + it('should do nothing if package type is undefined', () => { |
| 18 | + // Arrange |
| 19 | + const pkg: PackageJson = { name: 'foo', version: '1.0.0' } |
| 20 | + const pkgstring: string = JSON.stringify(pkg, null, 2) + '\n' |
| 21 | + vfs.writeFileSync('./package.json', pkgstring) |
| 22 | + |
| 23 | + // Act |
| 24 | + testSubject() |
| 25 | + |
| 26 | + // Expect |
| 27 | + expect(vfs.readFileSync('./package.json', 'utf8')).to.equal(pkgstring) |
| 28 | + }) |
| 29 | + |
| 30 | + describe('disable', () => { |
| 31 | + const pkg: PackageJson = { type: 'module' } |
| 32 | + |
| 33 | + beforeEach(() => { |
| 34 | + vfs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n') |
| 35 | + }) |
| 36 | + |
| 37 | + it('should disable package type with "off"', () => { |
| 38 | + // Act |
| 39 | + testSubject('off') |
| 40 | + |
| 41 | + // Expect |
| 42 | + expect(JSON.parse(vfs.readFileSync('./package.json', 'utf8') as string)) |
| 43 | + .to.have.property('#type') |
| 44 | + .that.equals(pkg.type) |
| 45 | + }) |
| 46 | + |
| 47 | + it('should disable package type without command', () => { |
| 48 | + // Act |
| 49 | + testSubject() |
| 50 | + |
| 51 | + // Expect |
| 52 | + expect(JSON.parse(vfs.readFileSync('./package.json', 'utf8') as string)) |
| 53 | + .to.have.property('#type') |
| 54 | + .that.equals(pkg.type) |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + describe('enable', () => { |
| 59 | + const pkg: PackageJson = { '#type': 'module' } |
| 60 | + |
| 61 | + beforeEach(() => { |
| 62 | + vfs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n') |
| 63 | + }) |
| 64 | + |
| 65 | + it('should enable package type with "on"', () => { |
| 66 | + // Act |
| 67 | + testSubject('on') |
| 68 | + |
| 69 | + // Expect |
| 70 | + expect(JSON.parse(vfs.readFileSync('./package.json', 'utf8') as string)) |
| 71 | + .to.have.property('type') |
| 72 | + .that.equals(pkg['#type']) |
| 73 | + }) |
| 74 | + |
| 75 | + it('should enable package type without command', () => { |
| 76 | + // Act |
| 77 | + testSubject() |
| 78 | + |
| 79 | + // Expect |
| 80 | + expect(JSON.parse(vfs.readFileSync('./package.json', 'utf8') as string)) |
| 81 | + .to.have.property('type') |
| 82 | + .that.equals(pkg['#type']) |
| 83 | + }) |
| 84 | + }) |
| 85 | +}) |
0 commit comments