mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Add tests around migration files (#7016)
This commit is contained in:
parent
2e188ce4ef
commit
237d0b4d41
15
development/generate-migration.sh
Executable file
15
development/generate-migration.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#! /bin/bash
|
||||
g-migration() {
|
||||
[[ -z "$1" ]] && { echo "Migration version is required!" ; exit 1; }
|
||||
local vnum=$1
|
||||
if (($1 < 100)); then
|
||||
vnum=0$1
|
||||
fi
|
||||
touch app/scripts/migrations/"$vnum".js
|
||||
cp app/scripts/migrations/template.js app/scripts/migrations/"$vnum".js
|
||||
|
||||
touch test/unit/migrations/"$vnum".js
|
||||
cp test/unit/migrations/template-test.js test/unit/migrations/"$vnum"-test.js
|
||||
}
|
||||
|
||||
g-migration "$1"
|
@ -51,7 +51,8 @@
|
||||
"version:bump": "node development/run-version-bump.js",
|
||||
"storybook": "start-storybook -p 6006 -c .storybook",
|
||||
"update-changelog": "./development/auto-changelog.sh",
|
||||
"rollback": "./development/rollback.sh"
|
||||
"rollback": "./development/rollback.sh",
|
||||
"generate:migration": "./development/generate-migration.sh"
|
||||
},
|
||||
"resolutions": {
|
||||
"3box/ipfs/ipld-zcash/zcash-bitcore-lib/lodash": "^4.17.12",
|
||||
|
@ -1,5 +1,7 @@
|
||||
const fs = require('fs')
|
||||
const assert = require('assert')
|
||||
const clone = require('clone')
|
||||
const pify = require('pify')
|
||||
const Migrator = require('../../../app/scripts/lib/migrator/')
|
||||
const liveMigrations = require('../../../app/scripts/migrations/')
|
||||
const stubMigrations = [
|
||||
@ -35,6 +37,23 @@ const firstTimeState = {
|
||||
meta: { version: 0 },
|
||||
data: require('../../../app/scripts/first-time-state'),
|
||||
}
|
||||
describe('liveMigrations require list', () => {
|
||||
it('should include all the migrations', async () => {
|
||||
const fileNames = await pify(cb => fs.readdir('./app/scripts/migrations/', cb))()
|
||||
const migrationNumbers = fileNames.reduce((agg, filename) => {
|
||||
const name = filename.split('.')[0]
|
||||
if (/^\d+$/.test(name)) {
|
||||
agg.push(name)
|
||||
}
|
||||
return agg
|
||||
}, []).map((num) => parseInt(num))
|
||||
|
||||
migrationNumbers.forEach((num) => {
|
||||
const migration = liveMigrations.find((m) => m.version === num)
|
||||
assert(migration, `migration should be include in the index missing migration ${num}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Migrator', () => {
|
||||
const migrator = new Migrator({ migrations: stubMigrations })
|
||||
|
Loading…
Reference in New Issue
Block a user