Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should continue to save', async () => {
let called = 0;
// Lower the duration multiplier.
(handler as any)._multiplier = 1;
let promise = testEmission(context.fileChanged, {
test: () => {
if (called === 0) {
context.model.fromString('bar');
called++;
}
return called === 1;
}
});
context.model.fromString('foo');
expect(handler.isActive).to.equal(false);
handler.saveInterval = 1;
handler.start();
return promise;
});
it('should reject if the test throws an error', async () => {
const owner = {};
const x = new Signal<{}, number>(owner);
const emission = testEmission(x, {
find: (a, b) => b === 1,
test: (a, b) => {
throw new Error('my error');
},
value: 'done'
});
x.emit(0);
expect(await isFulfilled(emission)).to.equal(false);
x.emit(1);
await expectFailure(emission, 'my error');
});
it('should be emitted when the running sessions changed', async () => {
let promise = testEmission(manager.runningChanged, {
test: (sender, args) => {
expect(sender).to.equal(manager);
expect(toArray(args).length).to.be.greaterThan(0);
}
});
await startNew(manager);
await promise;
});
it('should be emitted for an unhandled message', async () => {
const tester = new SessionTester();
const session = await tester.startSession();
await session.kernel.ready;
const msgId = UUID.uuid4();
const emission = testEmission(session.unhandledMessage, {
find: (k, msg) => msg.header.msg_id === msgId
});
const msg = KernelMessage.createMessage({
msgType: 'kernel_info_request',
channel: 'shell',
session: tester.serverSessionId,
msgId,
content: {}
});
msg.parent_header = { session: session.kernel.clientId };
tester.send(msg);
await emission;
await tester.shutdown();
tester.dispose();
});
});
it('should change the document contents', async () => {
RENDERMIME.addFactory(fooFactory);
await dContext.initialize(true);
const emission = testEmission(dContext.model.contentChanged, {
test: () => {
expect(dContext.model.toString()).to.equal('bar');
}
});
const renderer = RENDERMIME.createRenderer('text/foo');
const widget = new LogRenderer({
context: dContext,
renderer,
mimeType: 'text/foo',
renderTimeout: 1000,
dataType: 'string'
});
await widget.ready;
await emission;
});
});
it('should emit a runningChanged signal', async () => {
session = await manager.startNew();
const emission = testEmission(manager.runningChanged, {
test: () => {
expect(session.isDisposed).to.equal(false);
}
});
await manager.shutdown(session.name);
await emission;
});
});
it('should emit `"reconnecting"`, then `"connected"` status', async () => {
let connectedEmission: Promise;
const emission = testEmission(defaultKernel.statusChanged, {
find: () => defaultKernel.status === 'reconnecting',
test: () => {
connectedEmission = testEmission(defaultKernel.statusChanged, {
find: () => defaultKernel.status === 'connected'
});
}
});
await defaultKernel.reconnect();
await emission;
await connectedEmission;
});
});
it('should resolve to the given value', async () => {
const owner = {};
const x = new Signal<{}, number>(owner);
const emission = testEmission(x, {
value: 'done'
});
x.emit(0);
expect(await emission).to.equal('done');
});
it('should not emit when a widget has been injected', async () => {
const one = createWidget();
const two = createWidget();
let total = 0;
let promise = testEmission(tracker.currentChanged, {
find: () => {
return total === 1;
}
});
tracker.widgetAdded.connect(() => {
total++;
});
void tracker.add(one);
void tracker.inject(two);
Widget.attach(two, document.body);
focus(two);
Widget.detach(two);
await promise;
one.dispose();
two.dispose();
test: () => {
connectedEmission = testEmission(defaultKernel.statusChanged, {
find: () => defaultKernel.status === 'connected'
});
}
});