Commit ba5b5395 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '37619-fix-vue-typeerror-not-failing-the-build' into 'master'

Stop "ERROR: TypeError{}" from being logged to the console and fail tests

Closes #37619

See merge request gitlab-org/gitlab-ce!15830
parents d8722e80 05e61c36
...@@ -123,9 +123,7 @@ ...@@ -123,9 +123,7 @@
// we need to do this to prevent noteForm inconsistent content warning // we need to do this to prevent noteForm inconsistent content warning
// this is something we intentionally do so we need to recover the content // this is something we intentionally do so we need to recover the content
this.note.note = noteText; this.note.note = noteText;
if (this.$refs.noteBody) { this.$refs.noteBody.$refs.noteForm.note = noteText;
this.$refs.noteBody.$refs.noteForm.note = noteText; // TODO: This could be better
}
}, },
}, },
created() { created() {
......
...@@ -2,23 +2,12 @@ import Vue from 'vue'; ...@@ -2,23 +2,12 @@ import Vue from 'vue';
import notesApp from '~/notes/components/notes_app.vue'; import notesApp from '~/notes/components/notes_app.vue';
import service from '~/notes/services/notes_service'; import service from '~/notes/services/notes_service';
import * as mockData from '../mock_data'; import * as mockData from '../mock_data';
import getSetTimeoutPromise from '../../helpers/set_timeout_promise_helper';
describe('note_app', () => { describe('note_app', () => {
let mountComponent; let mountComponent;
let vm; let vm;
const individualNoteInterceptor = (request, next) => {
next(request.respondWith(JSON.stringify(mockData.individualNoteServerResponse), {
status: 200,
}));
};
const discussionNoteInterceptor = (request, next) => {
next(request.respondWith(JSON.stringify(mockData.discussionNoteServerResponse), {
status: 200,
}));
};
beforeEach(() => { beforeEach(() => {
const IssueNotesApp = Vue.extend(notesApp); const IssueNotesApp = Vue.extend(notesApp);
...@@ -74,16 +63,16 @@ describe('note_app', () => { ...@@ -74,16 +63,16 @@ describe('note_app', () => {
describe('render', () => { describe('render', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(individualNoteInterceptor); Vue.http.interceptors.push(mockData.individualNoteInterceptor);
vm = mountComponent(); vm = mountComponent();
}); });
afterEach(() => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, individualNoteInterceptor); Vue.http.interceptors = _.without(Vue.http.interceptors, mockData.individualNoteInterceptor);
}); });
it('should render list of notes', (done) => { it('should render list of notes', (done) => {
const note = mockData.individualNoteServerResponse[0].notes[0]; const note = mockData.INDIVIDUAL_NOTE_RESPONSE_MAP.GET['/gitlab-org/gitlab-ce/issues/26/discussions.json'][0].notes[0];
setTimeout(() => { setTimeout(() => {
expect( expect(
...@@ -129,13 +118,16 @@ describe('note_app', () => { ...@@ -129,13 +118,16 @@ describe('note_app', () => {
describe('update note', () => { describe('update note', () => {
describe('individual note', () => { describe('individual note', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(individualNoteInterceptor); Vue.http.interceptors.push(mockData.individualNoteInterceptor);
spyOn(service, 'updateNote').and.callFake(() => Promise.resolve()); spyOn(service, 'updateNote').and.callThrough();
vm = mountComponent(); vm = mountComponent();
}); });
afterEach(() => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, individualNoteInterceptor); Vue.http.interceptors = _.without(
Vue.http.interceptors,
mockData.individualNoteInterceptor,
);
}); });
it('renders edit form', (done) => { it('renders edit form', (done) => {
...@@ -149,28 +141,36 @@ describe('note_app', () => { ...@@ -149,28 +141,36 @@ describe('note_app', () => {
}); });
it('calls the service to update the note', (done) => { it('calls the service to update the note', (done) => {
setTimeout(() => { getSetTimeoutPromise()
vm.$el.querySelector('.js-note-edit').click(); .then(() => {
Vue.nextTick(() => { vm.$el.querySelector('.js-note-edit').click();
})
.then(Vue.nextTick)
.then(() => {
vm.$el.querySelector('.js-vue-issue-note-form').value = 'this is a note'; vm.$el.querySelector('.js-vue-issue-note-form').value = 'this is a note';
vm.$el.querySelector('.js-vue-issue-save').click(); vm.$el.querySelector('.js-vue-issue-save').click();
expect(service.updateNote).toHaveBeenCalled(); expect(service.updateNote).toHaveBeenCalled();
done(); })
}); // Wait for the requests to finish before destroying
}, 0); .then(Vue.nextTick)
.then(done)
.catch(done.fail);
}); });
}); });
describe('dicussion note', () => { describe('dicussion note', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(discussionNoteInterceptor); Vue.http.interceptors.push(mockData.discussionNoteInterceptor);
spyOn(service, 'updateNote').and.callFake(() => Promise.resolve()); spyOn(service, 'updateNote').and.callThrough();
vm = mountComponent(); vm = mountComponent();
}); });
afterEach(() => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, discussionNoteInterceptor); Vue.http.interceptors = _.without(
Vue.http.interceptors,
mockData.discussionNoteInterceptor,
);
}); });
it('renders edit form', (done) => { it('renders edit form', (done) => {
...@@ -184,16 +184,21 @@ describe('note_app', () => { ...@@ -184,16 +184,21 @@ describe('note_app', () => {
}); });
it('updates the note and resets the edit form', (done) => { it('updates the note and resets the edit form', (done) => {
setTimeout(() => { getSetTimeoutPromise()
vm.$el.querySelector('.js-note-edit').click(); .then(() => {
Vue.nextTick(() => { vm.$el.querySelector('.js-note-edit').click();
})
.then(Vue.nextTick)
.then(() => {
vm.$el.querySelector('.js-vue-issue-note-form').value = 'this is a note'; vm.$el.querySelector('.js-vue-issue-note-form').value = 'this is a note';
vm.$el.querySelector('.js-vue-issue-save').click(); vm.$el.querySelector('.js-vue-issue-save').click();
expect(service.updateNote).toHaveBeenCalled(); expect(service.updateNote).toHaveBeenCalled();
done(); })
}); // Wait for the requests to finish before destroying
}, 0); .then(Vue.nextTick)
.then(done)
.catch(done.fail);
}); });
}); });
}); });
...@@ -216,12 +221,12 @@ describe('note_app', () => { ...@@ -216,12 +221,12 @@ describe('note_app', () => {
describe('edit form', () => { describe('edit form', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(individualNoteInterceptor); Vue.http.interceptors.push(mockData.individualNoteInterceptor);
vm = mountComponent(); vm = mountComponent();
}); });
afterEach(() => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, individualNoteInterceptor); Vue.http.interceptors = _.without(Vue.http.interceptors, mockData.individualNoteInterceptor);
}); });
it('should render markdown docs url', (done) => { it('should render markdown docs url', (done) => {
......
...@@ -312,138 +312,212 @@ export const loggedOutnoteableData = { ...@@ -312,138 +312,212 @@ export const loggedOutnoteableData = {
"preview_note_path": "/gitlab-org/gitlab-ce/preview_markdown?quick_actions_target_id=98&quick_actions_target_type=Issue" "preview_note_path": "/gitlab-org/gitlab-ce/preview_markdown?quick_actions_target_id=98&quick_actions_target_type=Issue"
} }
export const individualNoteServerResponse = [{ export const INDIVIDUAL_NOTE_RESPONSE_MAP = {
"id": "0fb4e0e3f9276e55ff32eb4195add694aece4edd", 'GET': {
"reply_id": "0fb4e0e3f9276e55ff32eb4195add694aece4edd", '/gitlab-org/gitlab-ce/issues/26/discussions.json': [{
"expanded": true, "id": "0fb4e0e3f9276e55ff32eb4195add694aece4edd",
"notes": [{ "reply_id": "0fb4e0e3f9276e55ff32eb4195add694aece4edd",
"id": 1390, "expanded": true,
"attachment": { "notes": [{
"url": null, "id": 1390,
"filename": null, "attachment": {
"image": false "url": null,
}, "filename": null,
"author": { "image": false
"id": 1, },
"name": "Root", "author": {
"username": "root", "id": 1,
"state": "active", "name": "Root",
"avatar_url": null, "username": "root",
"path": "/root" "state": "active",
}, "avatar_url": null,
"created_at": "2017-08-01T17:09:33.762Z", "path": "/root"
"updated_at": "2017-08-01T17:09:33.762Z", },
"system": false, "created_at": "2017-08-01T17:09:33.762Z",
"noteable_id": 98, "updated_at": "2017-08-01T17:09:33.762Z",
"noteable_type": "Issue", "system": false,
"type": null, "noteable_id": 98,
"human_access": "Owner", "noteable_type": "Issue",
"note": "sdfdsaf", "type": null,
"note_html": "\u003cp dir=\"auto\"\u003esdfdsaf\u003c/p\u003e", "human_access": "Owner",
"current_user": { "note": "sdfdsaf",
"can_edit": true "note_html": "\u003cp dir=\"auto\"\u003esdfdsaf\u003c/p\u003e",
"current_user": {
"can_edit": true
},
"discussion_id": "0fb4e0e3f9276e55ff32eb4195add694aece4edd",
"emoji_awardable": true,
"award_emoji": [{
"name": "baseball",
"user": {
"id": 1,
"name": "Root",
"username": "root"
}
}, {
"name": "art",
"user": {
"id": 1,
"name": "Root",
"username": "root"
}
}],
"toggle_award_path": "/gitlab-org/gitlab-ce/notes/1390/toggle_award_emoji",
"report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1390\u0026user_id=1",
"path": "/gitlab-org/gitlab-ce/notes/1390"
}],
"individual_note": true
}, {
"id": "70d5c92a4039a36c70100c6691c18c27e4b0a790",
"reply_id": "70d5c92a4039a36c70100c6691c18c27e4b0a790",
"expanded": true,
"notes": [{
"id": 1391,
"attachment": {
"url": null,
"filename": null,
"image": false
},
"author": {
"id": 1,
"name": "Root",
"username": "root",
"state": "active",
"avatar_url": null,
"path": "/root"
},
"created_at": "2017-08-02T10:51:38.685Z",
"updated_at": "2017-08-02T10:51:38.685Z",
"system": false,
"noteable_id": 98,
"noteable_type": "Issue",
"type": null,
"human_access": "Owner",
"note": "New note!",
"note_html": "\u003cp dir=\"auto\"\u003eNew note!\u003c/p\u003e",
"current_user": {
"can_edit": true
},
"discussion_id": "70d5c92a4039a36c70100c6691c18c27e4b0a790",
"emoji_awardable": true,
"award_emoji": [],
"toggle_award_path": "/gitlab-org/gitlab-ce/notes/1391/toggle_award_emoji",
"report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1391\u0026user_id=1",
"path": "/gitlab-org/gitlab-ce/notes/1391"
}],
"individual_note": true
}],
'/gitlab-org/gitlab-ce/noteable/issue/98/notes': {
last_fetched_at: 1512900838,
notes: [],
}, },
"discussion_id": "0fb4e0e3f9276e55ff32eb4195add694aece4edd", },
"emoji_awardable": true, 'PUT': {
"award_emoji": [{ '/gitlab-org/gitlab-ce/notes/1471': {
"name": "baseball", "commands_changes": null,
"user": { "valid": true,
"id": 1471,
"attachment": null,
"author": {
"id": 1, "id": 1,
"name": "Root", "name": "Root",
"username": "root" "username": "root",
} "state": "active",
}, { "avatar_url": null,
"name": "art", "path": "/root"
"user": { },
"created_at": "2017-08-08T16:53:00.666Z",
"updated_at": "2017-12-10T11:03:21.876Z",
"system": false,
"noteable_id": 124,
"noteable_type": "Issue",
"noteable_iid": 29,
"type": "DiscussionNote",
"human_access": "Owner",
"note": "Adding a comment",
"note_html": "\u003cp dir=\"auto\"\u003eAdding a comment\u003c/p\u003e",
"last_edited_at": "2017-12-10T11:03:21.876Z",
"last_edited_by": {
"id": 1, "id": 1,
"name": "Root", "name": 'Root',
"username": "root" "username": 'root',
} "state": 'active',
}], "avatar_url": null,
"toggle_award_path": "/gitlab-org/gitlab-ce/notes/1390/toggle_award_emoji", "path": '/root',
"report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1390\u0026user_id=1", },
"path": "/gitlab-org/gitlab-ce/notes/1390" "current_user": {
}], "can_edit": true
"individual_note": true },
}, { "discussion_id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052",
"id": "70d5c92a4039a36c70100c6691c18c27e4b0a790", "emoji_awardable": true,
"reply_id": "70d5c92a4039a36c70100c6691c18c27e4b0a790", "award_emoji": [],
"expanded": true, "toggle_award_path": "/gitlab-org/gitlab-ce/notes/1471/toggle_award_emoji",
"notes": [{ "report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F29%23note_1471\u0026user_id=1",
"id": 1391, "path": "/gitlab-org/gitlab-ce/notes/1471"
"attachment": {
"url": null,
"filename": null,
"image": false
},
"author": {
"id": 1,
"name": "Root",
"username": "root",
"state": "active",
"avatar_url": null,
"path": "/root"
},
"created_at": "2017-08-02T10:51:38.685Z",
"updated_at": "2017-08-02T10:51:38.685Z",
"system": false,
"noteable_id": 98,
"noteable_type": "Issue",
"type": null,
"human_access": "Owner",
"note": "New note!",
"note_html": "\u003cp dir=\"auto\"\u003eNew note!\u003c/p\u003e",
"current_user": {
"can_edit": true
}, },
"discussion_id": "70d5c92a4039a36c70100c6691c18c27e4b0a790", }
"emoji_awardable": true, };
"award_emoji": [],
"toggle_award_path": "/gitlab-org/gitlab-ce/notes/1391/toggle_award_emoji",
"report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1391\u0026user_id=1",
"path": "/gitlab-org/gitlab-ce/notes/1391"
}],
"individual_note": true
}];
export const discussionNoteServerResponse = [{ export const DISCUSSION_NOTE_RESPONSE_MAP = {
"id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052", ...INDIVIDUAL_NOTE_RESPONSE_MAP,
"reply_id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052", 'GET': {
"expanded": true, ...INDIVIDUAL_NOTE_RESPONSE_MAP.GET,
"notes": [{ '/gitlab-org/gitlab-ce/issues/26/discussions.json': [{
"id": 1471, "id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052",
"attachment": { "reply_id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052",
"url": null, "expanded": true,
"filename": null, "notes": [{
"image": false "id": 1471,
}, "attachment": {
"author": { "url": null,
"id": 1, "filename": null,
"name": "Root", "image": false
"username": "root", },
"state": "active", "author": {
"avatar_url": null, "id": 1,
"path": "/root" "name": "Root",
}, "username": "root",
"created_at": "2017-08-08T16:53:00.666Z", "state": "active",
"updated_at": "2017-08-08T16:53:00.666Z", "avatar_url": null,
"system": false, "path": "/root"
"noteable_id": 124, },
"noteable_type": "Issue", "created_at": "2017-08-08T16:53:00.666Z",
"noteable_iid": 29, "updated_at": "2017-08-08T16:53:00.666Z",
"type": "DiscussionNote", "system": false,
"human_access": "Owner", "noteable_id": 124,
"note": "Adding a comment", "noteable_type": "Issue",
"note_html": "\u003cp dir=\"auto\"\u003eAdding a comment\u003c/p\u003e", "noteable_iid": 29,
"current_user": { "type": "DiscussionNote",
"can_edit": true "human_access": "Owner",
}, "note": "Adding a comment",
"discussion_id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052", "note_html": "\u003cp dir=\"auto\"\u003eAdding a comment\u003c/p\u003e",
"emoji_awardable": true, "current_user": {
"award_emoji": [], "can_edit": true
"toggle_award_path": "/gitlab-org/gitlab-ce/notes/1471/toggle_award_emoji", },
"report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F29%23note_1471\u0026user_id=1", "discussion_id": "a3ed36e29b1957efb3b68c53e2d7a2b24b1df052",
"path": "/gitlab-org/gitlab-ce/notes/1471" "emoji_awardable": true,
}], "award_emoji": [],
"individual_note": false "toggle_award_path": "/gitlab-org/gitlab-ce/notes/1471/toggle_award_emoji",
}]; "report_abuse_path": "/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F29%23note_1471\u0026user_id=1",
"path": "/gitlab-org/gitlab-ce/notes/1471"
}],
"individual_note": false
}],
},
};
export function individualNoteInterceptor(request, next) {
const body = INDIVIDUAL_NOTE_RESPONSE_MAP[request.method.toUpperCase()][request.url];
next(request.respondWith(JSON.stringify(body), {
status: 200,
}));
}
export function discussionNoteInterceptor(request, next) {
const body = DISCUSSION_NOTE_RESPONSE_MAP[request.method.toUpperCase()][request.url];
next(request.respondWith(JSON.stringify(body), {
status: 200,
}));
}
...@@ -17,6 +17,12 @@ Vue.config.warnHandler = (msg, vm, trace) => { ...@@ -17,6 +17,12 @@ Vue.config.warnHandler = (msg, vm, trace) => {
fail(`${msg}${trace}`); fail(`${msg}${trace}`);
}; };
let hasVueErrors = false;
Vue.config.errorHandler = function (err) {
hasVueErrors = true;
fail(err);
};
Vue.use(VueResource); Vue.use(VueResource);
// enable test fixtures // enable test fixtures
...@@ -72,7 +78,7 @@ testsContext.keys().forEach(function (path) { ...@@ -72,7 +78,7 @@ testsContext.keys().forEach(function (path) {
describe('test errors', () => { describe('test errors', () => {
beforeAll((done) => { beforeAll((done) => {
if (hasUnhandledPromiseRejections || hasVueWarnings) { if (hasUnhandledPromiseRejections || hasVueWarnings || hasVueErrors) {
setTimeout(done, 1000); setTimeout(done, 1000);
} else { } else {
done(); done();
...@@ -86,6 +92,10 @@ describe('test errors', () => { ...@@ -86,6 +92,10 @@ describe('test errors', () => {
it('has no Vue warnings', () => { it('has no Vue warnings', () => {
expect(hasVueWarnings).toBe(false); expect(hasVueWarnings).toBe(false);
}); });
it('has no Vue error', () => {
expect(hasVueErrors).toBe(false);
});
}); });
// if we're generating coverage reports, make sure to include all files so // if we're generating coverage reports, make sure to include all files so
......
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