|
|
@ -60,33 +60,27 @@ describe('liveMigrations require list', () => { |
|
|
|
|
|
|
|
|
|
|
|
describe('Migrator', () => { |
|
|
|
describe('Migrator', () => { |
|
|
|
const migrator = new Migrator({ migrations: stubMigrations }) |
|
|
|
const migrator = new Migrator({ migrations: stubMigrations }) |
|
|
|
it('migratedData version should be version 3', (done) => { |
|
|
|
it('migratedData version should be version 3', async () => { |
|
|
|
migrator.migrateData(versionedData) |
|
|
|
const migratedData = await migrator.migrateData(versionedData) |
|
|
|
.then((migratedData) => { |
|
|
|
|
|
|
|
assert.equal(migratedData.meta.version, stubMigrations[2].version) |
|
|
|
assert.equal(migratedData.meta.version, stubMigrations[2].version) |
|
|
|
done() |
|
|
|
|
|
|
|
}).catch(done) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('should match the last version in live migrations', (done) => { |
|
|
|
it('should match the last version in live migrations', async () => { |
|
|
|
const migrator = new Migrator({ migrations: liveMigrations }) |
|
|
|
const migrator = new Migrator({ migrations: liveMigrations }) |
|
|
|
migrator.migrateData(firstTimeState) |
|
|
|
const migratedData = await migrator.migrateData(firstTimeState) |
|
|
|
.then((migratedData) => { |
|
|
|
|
|
|
|
const last = liveMigrations.length - 1 |
|
|
|
const last = liveMigrations.length - 1 |
|
|
|
assert.equal(migratedData.meta.version, liveMigrations[last].version) |
|
|
|
assert.equal(migratedData.meta.version, liveMigrations[last].version) |
|
|
|
done() |
|
|
|
|
|
|
|
}).catch(done) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('should emit an error', function (done) { |
|
|
|
it('should emit an error', async () => { |
|
|
|
this.timeout(15000) |
|
|
|
const migrator = new Migrator({ |
|
|
|
const migrator = new Migrator({ migrations: [{ version: 1, migrate: async () => { |
|
|
|
migrations: [{ |
|
|
|
|
|
|
|
version: 1, |
|
|
|
|
|
|
|
async migrate () { |
|
|
|
throw new Error('test') |
|
|
|
throw new Error('test') |
|
|
|
} } ] }) |
|
|
|
}, |
|
|
|
migrator.on('error', () => done()) |
|
|
|
}], |
|
|
|
migrator.migrateData({ meta: { version: 0 } }) |
|
|
|
}) |
|
|
|
.then(() => { |
|
|
|
await assert.rejects(migrator.migrateData({ meta: { version: 0 } })) |
|
|
|
}).catch(done) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|