-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: rewrite generate test * feat: improvements * feat: run prettier on all files * feat: add simple reset test * feat: fixes
- Loading branch information
Showing
8 changed files
with
81 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
const { execaNode } = require('execa') | ||
const fs = require('fs') | ||
const { join } = require('path') | ||
const { handler: generateCommand } = require('../bin/commands/generate') | ||
const { extractLogLinesFromConsole } = require('../__test-utils__/log') | ||
|
||
//todo: rewrite to match refactored other tests? | ||
describe('generate', () => { | ||
it('should create a new migration file', async () => { | ||
const stdout = extractLogLinesFromConsole() | ||
const migrationName = 'test-migration' | ||
const { stdout } = await execaNode('./bin/cmp.js', ['generate', migrationName]) | ||
await generateCommand({ name: migrationName }) | ||
|
||
const migrationFileName = stdout.split(' ').find((m) => m.indexOf('js') > -1) | ||
const migrationFile = fs.readFileSync(`${process.env.MIGRATIONS_DIR}/${migrationFileName}`, 'utf-8') | ||
let numberOfMigrationsInMigrationsDir = fs.readdirSync(process.env.MIGRATIONS_DIR).length | ||
expect(numberOfMigrationsInMigrationsDir).toBe(1) | ||
|
||
const migrationFileName = stdout[0].split(' ').find((m) => m.indexOf('js') > -1) | ||
const migrationFilePath = `${process.env.MIGRATIONS_DIR}/${migrationFileName}` | ||
const migrationFile = fs.readFileSync(migrationFilePath, 'utf-8') | ||
const template = fs.readFileSync(join(__dirname, '..', 'templates', 'migration.mustache'), 'utf8') | ||
|
||
expect(migrationFile).toEqual(template) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { handler: resetCommand } = require('../bin/commands/reset') | ||
const { extractLogLinesFromConsole } = require('../__test-utils__/log') | ||
|
||
describe('reset', () => { | ||
it('should not reset environment if on master', async () => { | ||
const stdout = extractLogLinesFromConsole() | ||
await resetCommand({ force: false }) | ||
expect(stdout).toContain(`Can't reset environment if you are on master.`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const fs = require('fs') | ||
const { join } = require('path') | ||
const { handler: rollbackCommand } = require('../bin/commands/rollback') | ||
const { extractLogLinesFromConsole } = require('../__test-utils__/log') | ||
const { handler: migrateCommand } = require('../bin/commands/migrate') | ||
|
||
describe('rollback', () => { | ||
it('should demand user to use "--force" flag if running against master space', async () => { | ||
const stdout = extractLogLinesFromConsole() | ||
await rollbackCommand({ force: false }) | ||
expect(stdout).toContain('Executing migrations against master requires the --force flag.') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters