describe('#cliPkgTask', () => { it('should return yarn --production as first command', () => { const command = util.cliPkgTask('thing'); command[0].should.equal('yarn install --production'); }); const command = util.cliPkgTask('thing'); const parts = command[1].split(' '); parts[7].should.equal('thing'); }); const command = util.cliPkgTask('thing'); const os = command[1].split(' ')[3].split('-')[1]; os.should.equal(target); }); setPlatform('darwin'); const c1 = util.cliPkgTask('thing'); c1[2].should.equal('chmod +x thing'); c1[3].should.equal('sleep 2'); resetPlatform(); setPlatform('linux'); const c2 = util.cliPkgTask('thing'); c2[2].should.equal('chmod +x thing'); c2[3].should.equal('sleep 2'); resetPlatform(); }); setPlatform('win32'); const command = util.cliPkgTask('thing');
it('should return a Log instance with correct default options', () => { const log = new Log(); log.should.be.instanceof(EventEmitter); log.should.have.property('exitOnError', true); log.transports.should.be.an('object').with.property('console'); log.transports.console.should.be.instanceof(EventEmitter); log.transports.console.should.have.property('level', 'warn'); _.forEach(['error', 'warn', 'info', 'verbose', 'debug', 'silly'], level => { log[level].should.be.a('function'); }); }); log.transports.console.should.have.property('level', 'info'); }); _.forEach(logLevels, (word, num) => { const log = new Log({logLevelConsole: _.toInteger(num)}); log.transports.console.should.have.property('level', word); }); }); filesystem(); const log = new Log({logDir: '/tmp/logz', logLevel: 'warn'}); fs.existsSync('/tmp/logz').should.be.true; _.forEach(['error-file', 'log-file'], transport => { log.transports.should.be.an('object').with.property(transport); log.transports[transport].should.be.instanceof(EventEmitter); log.transports[transport].should.have.property('level', 'warn'); });
return shell.sh(['slip', 'sliding', 'away']) .then(result => { result.should.equal('EXEC: slip sliding away'); }) .then(_shell.exec.restore()) .should.be.fulfilled; }); return shell.sh(['tupelo', 'honey', 'baby'], opts) .then(result => { result.should.equal('SPAWN: tupelo honey baby'); }) .should.be.fulfilled; }); child.spawn.restore(); const shell = new Shell(); sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['set', 'us', 'up', 'the', 'bomb'], {mode: 'attach'}).should.be.rejected .then(child.spawn.restore()); }); const shell = new Shell(); sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['van', 'the', 'man'], {detached: true}).should.be.fulfilled .then(child.spawn.restore()); }); process.lando = 'browser';
it('must have a persistentKey of type string', async () => { const persistenceEngine = new MockPersistenceEngine(); system = start(configurePersistence(persistenceEngine)); (() => persistentQuery(system, ignore, undefined)).should.throw(Error); (() => persistentQuery(system, ignore, null)).should.throw(Error); (() => persistentQuery(system, ignore, 1)).should.throw(Error); (() => persistentQuery(system, ignore, [])).should.throw(Error); (() => persistentQuery(system, ignore, {})).should.throw(Error); (() => persistentQuery(system, ignore, Symbol('A'))).should.throw(Error); });
describe('AbstractPersistenceEngine', function () { it('should throw when functions are invoked', function () { const event = new PersistedEvent({ msg: '234' }, 1, 'test-key', []); const snapshot = new PersistedSnapshot('234', 1, 'test-key'); const abstractEngine = new AbstractPersistenceEngine(); (() => abstractEngine.events('123', 1)).should.throw(Error); (() => abstractEngine.persist(event)).should.throw(Error); (() => abstractEngine.latestSnapshot('123')).should.throw(Error); (() => abstractEngine.takeSnapshot(snapshot)).should.throw(Error); }); });
it('should return undefined if no previous events', async function () { const persistenceEngine = new MockPersistenceEngine(); system = start(configurePersistence(persistenceEngine)); const query = persistentQuery( system, (concatenativeFunction('')), 'test' ); (await query() === undefined).should.equal(true); });
describe('Object with primitives serialization/deserialization', function() { let serializedTestObject, deserializedTestObject; it('Serialize object', function () { serializedTestObject = testObject.serialize(serializer); }); it('Deserialize object', function () { deserializedTestObject = serializer.deserialize(serializedTestObject.dataBuffer); deserializedTestObject.byteOffset.should.equal(1 + 4 + 4 + 2 + 1 + 1); //float precision is capped (deserializedTestObject.obj.float32 - testObject.float32).should.be.lessThan(0.00000001); deserializedTestObject.obj.int32.should.be.equal(testObject.int32); deserializedTestObject.obj.int16.should.be.equal(testObject.int16); deserializedTestObject.obj.int8.should.be.equal(testObject.int8); deserializedTestObject.obj.uint8.should.be.equal(testObject.uint8); }); });
describe('PersistedSnapshot', function () { describe('#data', function () { it('should disallow non-number sequenceNums', function () { (() => new PersistedSnapshot({ msg: 'test' }, '1', 'test-key')).should.throw(Error); }); }); describe('#createdAt', function () { it('should be able to be explicitely set', function () { new PersistedSnapshot({ msg: 'test' }, 1, 'test-key', 123456).createdAt.should.equal(123456); }); it('should default to the current time', function () { const oldGetTime = global.Date.prototype.getTime; global.Date.prototype.getTime = () => 123456; new PersistedSnapshot({ msg: 'test' }, 1, 'test-key').createdAt.should.equal(123456); global.Date.prototype.getTime = oldGetTime; }); }); });
describe('#createChildPath()', function () { it('should append name to end of parts array if name is valid', function () { let path1 = ActorPath.root().createChildPath('a'); path1.parts.should.deep.equal(['a']); let path2 = path1.createChildPath('b'); path2.parts.should.deep.equal(['a', 'b']); let path3 = path2.createChildPath('c1234-d4'); path3.parts.should.deep.equal(['a', 'b', 'c1234-d4']); }); it('should throw an exception if the child name is invalid', function () { (() => ActorPath.root().createChildPath('$')).should.throw(Error); (() => ActorPath.root().createChildPath('a').createChildPath(' ')).should.throw(Error); (() => ActorPath.root().createChildPath('a').createChildPath('')).should.throw(Error); (() => ActorPath.root().createChildPath(undefined)).should.throw(Error); (() => ActorPath.root().createChildPath(null)).should.throw(Error); (() => ActorPath.root().createChildPath(123)).should.throw(Error); (() => ActorPath.root().createChildPath('.')).should.throw(Error); }); });
it('should throw an error if snapshotEvery is not a number', () => { const persistenceEngine = new MockPersistenceEngine(); system = start(configurePersistence(persistenceEngine)); (() => persistentQuery( system, concatenativeFunction('', () => delay(1000)), 'iceland', { snapshotEvery: 'a', snapshotKey: 'test' } )).should.throw(Error); });
// End helpers describe('#configurePersistence', () => { it('should require that the persistence engine be defined', function () { (() => configurePersistence(0)({})).should.throw(Error); (() => configurePersistence(undefined)({})).should.throw(Error); (() => configurePersistence(null)({})).should.throw(Error); (() => configurePersistence()({})).should.throw(Error); }); });
it('must have a persistentKey of type string', async () => { const persistenceEngine = new MockPersistenceEngine(); system = start(configurePersistence(persistenceEngine)); (() => spawnPersistent(system, ignore, undefined)).should.throw(Error); (() => spawnPersistent(system, ignore, null)).should.throw(Error); (() => spawnPersistent(system, ignore, 1)).should.throw(Error); (() => spawnPersistent(system, ignore, [])).should.throw(Error); (() => spawnPersistent(system, ignore, {})).should.throw(Error); (() => spawnPersistent(system, ignore, Symbol('A'))).should.throw(Error); });
it('should throw if snapshot is not a number', async function () { const persistenceEngine = new MockPersistenceEngine(); // Disable takeSnapshot system = start(configurePersistence(persistenceEngine)); (() => spawnPersistent(system, ignore, 'test1', undefined, { snapshotEvery: {} })).should.throw(Error); });
it('must have a snapshotKey of type string', async () => { const persistenceEngine = new MockPersistenceEngine(); system = start(configurePersistence(persistenceEngine)); (() => persistentQuery(system, ignore, 'abc', { snapshotEvery: 1, snapshotKey: undefined })).should.throw(Error); (() => persistentQuery(system, ignore, 'abc', { snapshotEvery: 1, snapshotKey: null })).should.throw(Error); (() => persistentQuery(system, ignore, 'abc', { snapshotEvery: 1, snapshotKey: 1 })).should.throw(Error); (() => persistentQuery(system, ignore, 'abc', { snapshotEvery: 1, snapshotKey: [] })).should.throw(Error); (() => persistentQuery(system, ignore, 'abc', { snapshotEvery: 1, snapshotKey: {} })).should.throw(Error); (() => persistentQuery(system, ignore, 'abc', { snapshotEvery: 1, snapshotKey: Symbol('A') })).should.throw(Error); });
it('should throw an error if cacheDuration is not a number', () => { const persistenceEngine = new MockPersistenceEngine(); system = start(configurePersistence(persistenceEngine)); (() => persistentQuery( system, concatenativeFunction('', () => delay(1000)), 'iceland', { cacheDuration: {}, snapshotKey: 'test' } )).should.throw(Error); });