Commit 9e72e5e6 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'winh-speedup-smartinterval-tests' into 'master'

Mock timeouts and Promise in SmartInterval tests

See merge request gitlab-org/gitlab-ce!20496
parents 5bd8bfb6 66ad04e4
export default () => new Promise(resolve => requestAnimationFrame(resolve));
...@@ -5,6 +5,7 @@ import { numberToHumanSize } from '~/lib/utils/number_utils'; ...@@ -5,6 +5,7 @@ import { numberToHumanSize } from '~/lib/utils/number_utils';
import '~/lib/utils/datetime_utility'; import '~/lib/utils/datetime_utility';
import Job from '~/job'; import Job from '~/job';
import '~/breakpoints'; import '~/breakpoints';
import waitForPromises from 'spec/helpers/wait_for_promises';
describe('Job', () => { describe('Job', () => {
const JOB_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1`; const JOB_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1`;
...@@ -12,10 +13,6 @@ describe('Job', () => { ...@@ -12,10 +13,6 @@ describe('Job', () => {
let response; let response;
let job; let job;
function waitForPromise() {
return new Promise(resolve => requestAnimationFrame(resolve));
}
preloadFixtures('builds/build-with-artifacts.html.raw'); preloadFixtures('builds/build-with-artifacts.html.raw');
beforeEach(() => { beforeEach(() => {
...@@ -49,7 +46,7 @@ describe('Job', () => { ...@@ -49,7 +46,7 @@ describe('Job', () => {
beforeEach(function (done) { beforeEach(function (done) {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
...@@ -93,7 +90,7 @@ describe('Job', () => { ...@@ -93,7 +90,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(() => { .then(() => {
expect($('#build-trace .js-build-output').text()).toMatch(/Update/); expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
expect(job.state).toBe('newstate'); expect(job.state).toBe('newstate');
...@@ -107,7 +104,7 @@ describe('Job', () => { ...@@ -107,7 +104,7 @@ describe('Job', () => {
}; };
}) })
.then(() => jasmine.clock().tick(4001)) .then(() => jasmine.clock().tick(4001))
.then(waitForPromise) .then(waitForPromises)
.then(() => { .then(() => {
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/); expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
expect(job.state).toBe('finalstate'); expect(job.state).toBe('finalstate');
...@@ -126,7 +123,7 @@ describe('Job', () => { ...@@ -126,7 +123,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(() => { .then(() => {
expect($('#build-trace .js-build-output').text()).toMatch(/Update/); expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
...@@ -137,7 +134,7 @@ describe('Job', () => { ...@@ -137,7 +134,7 @@ describe('Job', () => {
}; };
}) })
.then(() => jasmine.clock().tick(4001)) .then(() => jasmine.clock().tick(4001))
.then(waitForPromise) .then(waitForPromises)
.then(() => { .then(() => {
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/); expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
expect($('#build-trace .js-build-output').text()).toMatch(/Different/); expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
...@@ -160,7 +157,7 @@ describe('Job', () => { ...@@ -160,7 +157,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(() => { .then(() => {
expect(document.querySelector('.js-truncated-info').classList).not.toContain('hidden'); expect(document.querySelector('.js-truncated-info').classList).not.toContain('hidden');
}) })
...@@ -181,7 +178,7 @@ describe('Job', () => { ...@@ -181,7 +178,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(() => { .then(() => {
expect( expect(
document.querySelector('.js-truncated-info-size').textContent.trim(), document.querySelector('.js-truncated-info-size').textContent.trim(),
...@@ -203,7 +200,7 @@ describe('Job', () => { ...@@ -203,7 +200,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(() => { .then(() => {
expect( expect(
document.querySelector('.js-truncated-info-size').textContent.trim(), document.querySelector('.js-truncated-info-size').textContent.trim(),
...@@ -219,7 +216,7 @@ describe('Job', () => { ...@@ -219,7 +216,7 @@ describe('Job', () => {
}; };
}) })
.then(() => jasmine.clock().tick(4001)) .then(() => jasmine.clock().tick(4001))
.then(waitForPromise) .then(waitForPromises)
.then(() => { .then(() => {
expect( expect(
document.querySelector('.js-truncated-info-size').textContent.trim(), document.querySelector('.js-truncated-info-size').textContent.trim(),
...@@ -258,7 +255,7 @@ describe('Job', () => { ...@@ -258,7 +255,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(() => { .then(() => {
expect(document.querySelector('.js-truncated-info').classList).toContain('hidden'); expect(document.querySelector('.js-truncated-info').classList).toContain('hidden');
}) })
...@@ -280,7 +277,7 @@ describe('Job', () => { ...@@ -280,7 +277,7 @@ describe('Job', () => {
job = new Job(); job = new Job();
waitForPromise() waitForPromises()
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment