Merge remote-tracking branch 'origin/5.0' into parallel

This commit is contained in:
Steve Gravrock
2022-09-18 09:43:31 -07:00
9 changed files with 312 additions and 321 deletions

View File

@@ -1,5 +1,6 @@
describe('Env integration', function() {
let env;
const isBrowser = typeof window !== 'undefined';
beforeEach(function() {
jasmine.getEnv().registerIntegrationMatchers();
@@ -455,7 +456,7 @@ describe('Env integration', function() {
env.describe('A suite', function() {
env.it('fails', function(specDone) {
setTimeout(function() {
global.onerror('fail');
dispatchErrorEvent(global, { error: 'fail' });
specDone();
});
});
@@ -509,10 +510,14 @@ describe('Env integration', function() {
},
specDone: function() {
clearStackCallbacks[clearStackCallCount + 1] = function() {
global.onerror('fail at the end of the reporter queue');
dispatchErrorEvent(global, {
error: 'fail at the end of the reporter queue'
});
};
clearStackCallbacks[clearStackCallCount + 2] = function() {
global.onerror('fail at the end of the spec queue');
dispatchErrorEvent(global, {
error: 'fail at the end of the spec queue'
});
};
}
});
@@ -559,7 +564,7 @@ describe('Env integration', function() {
specDone();
queueMicrotask(function() {
queueMicrotask(function() {
global.onerror('fail');
dispatchErrorEvent(global, { error: 'fail' });
});
});
});
@@ -622,10 +627,14 @@ describe('Env integration', function() {
if (result.description === 'A nested suite') {
clearStackCallbacks[clearStackCallCount + 1] = function() {
global.onerror('fail at the end of the reporter queue');
dispatchErrorEvent(global, {
error: 'fail at the end of the reporter queue'
});
};
clearStackCallbacks[clearStackCallCount + 2] = function() {
global.onerror('fail at the end of the suite queue');
dispatchErrorEvent(global, {
error: 'fail at the end of the suite queue'
});
};
}
}
@@ -668,7 +677,7 @@ describe('Env integration', function() {
env.addReporter({
jasmineDone: function() {
global.onerror('a very late error');
dispatchErrorEvent(global, { error: 'a very late error' });
}
});
@@ -720,7 +729,7 @@ describe('Env integration', function() {
expectedErrors.push(`${msg} thrown`);
}
global.onerror(msg);
dispatchErrorEvent(global, { error: msg });
realClearStack(fn);
});
spyOn(console, 'error');
@@ -2547,15 +2556,24 @@ describe('Env integration', function() {
);
});
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(2);
expect(globalErrorSpy).toHaveBeenCalledWith(new Error('suite'));
expect(globalErrorSpy).toHaveBeenCalledWith(new Error('spec'));
}
});
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(
'async suite',
[/^(((Uncaught )?(exception: )?Error: suite( thrown)?)|(suite thrown))$/]
[/Error: suite/]
);
expect(reporter.specDone).toHaveFailedExpectationsForRunnable(
'suite async spec',
[/^(((Uncaught )?(exception: )?Error: spec( thrown)?)|(spec thrown))$/]
[/Error: spec/]
);
});
@@ -2689,14 +2707,14 @@ describe('Env integration', function() {
]);
env.addReporter(reporter);
global.onerror(
'Uncaught SyntaxError: Unexpected end of input',
'borkenSpec.js',
42,
undefined,
{ stack: 'a stack' }
);
global.onerror('Uncaught Error: ENOCHEESE');
dispatchErrorEvent(global, {
message: 'Uncaught SyntaxError: Unexpected end of input',
error: undefined,
filename: 'borkenSpec.js',
lineno: 42
});
const error = new Error('ENOCHEESE');
dispatchErrorEvent(global, { error });
await env.execute();
@@ -2706,15 +2724,15 @@ describe('Env integration', function() {
passed: false,
globalErrorType: 'load',
message: 'Uncaught SyntaxError: Unexpected end of input',
stack: 'a stack',
stack: undefined,
filename: 'borkenSpec.js',
lineno: 42
},
{
passed: false,
globalErrorType: 'load',
message: 'Uncaught Error: ENOCHEESE',
stack: undefined,
message: 'ENOCHEESE',
stack: error.stack,
filename: undefined,
lineno: undefined
}
@@ -2946,7 +2964,7 @@ describe('Env integration', function() {
env.addReporter(reporter);
env.it('passes', function() {});
global.onerror('Uncaught Error: ENOCHEESE');
dispatchErrorEvent(global, { error: 'ENOCHEESE' });
await env.execute();
expect(reporter.jasmineDone).toHaveBeenCalled();
@@ -3679,16 +3697,6 @@ describe('Env integration', function() {
expect(failedExpectations).toEqual([]);
});
it('calls the optional done callback when finished', function(done) {
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
env.addReporter(reporter);
env.execute(null, function() {
expect(reporter.jasmineDone).toHaveBeenCalled();
done();
});
});
describe('#spyOnGlobalErrorsAsync', function() {
const leftInstalledMessage =
'Global error spy was not uninstalled. ' +
@@ -3729,7 +3737,16 @@ describe('Env integration', function() {
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(2);
expect(globalErrorSpy).toHaveBeenCalledWith(new Error('nope'));
expect(globalErrorSpy).toHaveBeenCalledWith(new Error('yep'));
}
});
const passingResult = resultForRunable(
reporter.specDone,
@@ -3776,7 +3793,17 @@ describe('Env integration', function() {
'suiteDone'
]);
env.addReporter(reporter);
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(1);
expect(globalErrorSpy).toHaveBeenCalledWith(
new Error('should fail the spec')
);
}
});
const suiteResult = resultForRunable(reporter.suiteDone, 'Suite 1');
expect(suiteResult.status).toEqual('failed');
@@ -3821,7 +3848,17 @@ describe('Env integration', function() {
'suiteDone'
]);
env.addReporter(reporter);
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(1);
expect(globalErrorSpy).toHaveBeenCalledWith(
new Error('should fail the spec')
);
}
});
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(
'Suite 1',
@@ -3871,7 +3908,18 @@ describe('Env integration', function() {
'suiteDone'
]);
env.addReporter(reporter);
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(1);
expect(globalErrorSpy).toHaveBeenCalledWith(
new Error('should fail the spec')
);
}
});
const spec1Result = resultForRunable(reporter.specDone, 'Suite 1 a spec');
expect(spec1Result.status).toEqual('failed');
@@ -3907,7 +3955,17 @@ describe('Env integration', function() {
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(1);
expect(globalErrorSpy).toHaveBeenCalledWith(
new Error('should fail the spec')
);
}
});
const spec1Result = resultForRunable(reporter.specDone, 'spec 1');
expect(spec1Result.status).toEqual('failed');
@@ -3952,7 +4010,17 @@ describe('Env integration', function() {
'suiteDone'
]);
env.addReporter(reporter);
await env.execute();
await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
await env.execute();
if (isBrowser) {
// Verify that there were no unexpected errors
expect(globalErrorSpy).toHaveBeenCalledTimes(1);
expect(globalErrorSpy).toHaveBeenCalledWith(
new Error('should fail the spec')
);
}
});
const spec1Result = resultForRunable(reporter.specDone, 'Suite 1 a spec');
expect(spec1Result.status).toEqual('failed');
@@ -4010,8 +4078,25 @@ describe('Env integration', function() {
function browserEventMethods() {
return {
addEventListener() {},
removeEventListener() {}
listeners_: { error: [], unhandledrejection: [] },
addEventListener(eventName, listener) {
this.listeners_[eventName].push(listener);
},
removeEventListener(eventName, listener) {
this.listeners_[eventName] = this.listeners_[eventName].filter(
l => l !== listener
);
}
};
}
function dispatchErrorEvent(global, event) {
expect(global.listeners_.error.length)
.withContext('number of error listeners')
.toBeGreaterThan(0);
for (const l of global.listeners_.error) {
l(event);
}
}
});

View File

@@ -626,7 +626,7 @@ describe('spec running', function() {
expect(actions).toEqual(['spec2', 'spec3', 'spec1']);
});
it('refuses to re-enter suites with a beforeAll', function() {
it('refuses to re-enter suites with a beforeAll', async function() {
const actions = [];
let spec1;
let spec2;
@@ -648,13 +648,12 @@ describe('spec running', function() {
actions.push('spec3');
});
expect(function() {
env.execute([spec2.id, spec3.id, spec1.id]);
}).toThrowError(/beforeAll/);
const promise = env.execute([spec2.id, spec3.id, spec1.id]);
await expectAsync(promise).toBeRejectedWithError(/beforeAll/);
expect(actions).toEqual([]);
});
it('refuses to re-enter suites with a afterAll', function() {
it('refuses to re-enter suites with a afterAll', async function() {
const actions = [];
let spec1;
let spec2;
@@ -676,9 +675,8 @@ describe('spec running', function() {
actions.push('spec3');
});
expect(function() {
env.execute([spec2.id, spec3.id, spec1.id]);
}).toThrowError(/afterAll/);
const promise = env.execute([spec2.id, spec3.id, spec1.id]);
await expectAsync(promise).toBeRejectedWithError(/afterAll/);
expect(actions).toEqual([]);
});