|
| 1 | +import path from 'node:path' |
| 2 | +import { fileExists } from 'verdaccio/build/lib/utils' |
| 3 | +import { createTempDir, fileContainsText } from '../../helpers/files' |
| 4 | +import { SeccoCLI } from '../../helpers/invoke-cli' |
| 5 | + |
| 6 | +const initQuestion = 'What is the absolute path to your source?' |
| 7 | +const warning = '.seccorc file already exists in this directory' |
| 8 | + |
| 9 | +describe('init', () => { |
| 10 | + it('should work in directory without .seccorc file', () => { |
| 11 | + const [exitCode, logs] = SeccoCLI().setFixture('empty').invoke(['init']) |
| 12 | + |
| 13 | + logs.should.contain(initQuestion) |
| 14 | + logs.should.not.contain(warning) |
| 15 | + expect(exitCode).toBe(0) |
| 16 | + }) |
| 17 | + it('should warn in directory with .seccorc file', () => { |
| 18 | + const [exitCode, logs] = SeccoCLI().setFixture('existing-config-file').invoke(['init']) |
| 19 | + |
| 20 | + logs.should.contain(initQuestion) |
| 21 | + logs.should.contain(warning) |
| 22 | + expect(exitCode).toBe(0) |
| 23 | + }) |
| 24 | + it('should create config file after providing valid input', async () => { |
| 25 | + const [testDir, cleanup] = await createTempDir('init-command') |
| 26 | + const input = '/some/absolute/path/to/source' |
| 27 | + |
| 28 | + try { |
| 29 | + const [exitCode, logs] = SeccoCLI().setEnv({ TEST: undefined, VITEST: undefined, VITEST_MODE: undefined, VITEST_WORKER_ID: undefined, VITEST_POOL_ID: undefined }).setCwd(testDir).invoke(['init', '--source', input, '--yes']) |
| 30 | + |
| 31 | + logs.should.contain('Successfully created .seccorc') |
| 32 | + expect(exitCode).toBe(0) |
| 33 | + |
| 34 | + const file = await fileExists(path.join(testDir, '.seccorc')) |
| 35 | + expect(file).toBe(true) |
| 36 | + const contents = await fileContainsText(path.join(testDir, '.seccorc'), input) |
| 37 | + expect(contents).toBe(true) |
| 38 | + } |
| 39 | + finally { |
| 40 | + await cleanup() |
| 41 | + } |
| 42 | + }) |
| 43 | + it('should error on invalid input', () => { |
| 44 | + const [exitCode, logs] = SeccoCLI().setFixture('empty').invoke(['init', '--source', 'relative-path', '--yes']) |
| 45 | + |
| 46 | + logs.should.contain('You need to provide an absolute path for the --source flag.') |
| 47 | + expect(exitCode).toBe(1) |
| 48 | + }) |
| 49 | +}) |
0 commit comments