diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-26 09:11:02 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-26 09:11:02 +0000 |
commit | 47d07def1648ffc0787fe92ea5e351ccc5e9c4a4 (patch) | |
tree | a2d320f623a4f355049326b9e02ed74a3d3e9240 /spec | |
parent | 8bc752f208ea3c2c3218eb407033bd47471c2df5 (diff) | |
download | gitlab-ce-47d07def1648ffc0787fe92ea5e351ccc5e9c4a4.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
7 files changed, 79 insertions, 26 deletions
diff --git a/spec/frontend/__helpers__/vue_test_utils_helper.js b/spec/frontend/__helpers__/vue_test_utils_helper.js index a94cee84f74..2aae91f8a39 100644 --- a/spec/frontend/__helpers__/vue_test_utils_helper.js +++ b/spec/frontend/__helpers__/vue_test_utils_helper.js @@ -1,5 +1,5 @@ import * as testingLibrary from '@testing-library/dom'; -import { createWrapper, WrapperArray, mount, shallowMount } from '@vue/test-utils'; +import { createWrapper, WrapperArray, ErrorWrapper, mount, shallowMount } from '@vue/test-utils'; import { isArray, upperFirst } from 'lodash'; const vNodeContainsText = (vnode, text) => @@ -81,14 +81,9 @@ export const extendedWrapper = (wrapper) => { options, ); - // Return VTU `ErrorWrapper` if element is not found - // https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/error-wrapper.js - // VTU does not expose `ErrorWrapper` so, as of now, this is the best way to - // create an `ErrorWrapper` + // Element not found, return an `ErrorWrapper` if (!elements.length) { - const emptyElement = document.createElement('div'); - - return createWrapper(emptyElement).find('testing-library-element-not-found'); + return new ErrorWrapper(query); } return createWrapper(elements[0], this.options || {}); diff --git a/spec/frontend/__helpers__/vue_test_utils_helper_spec.js b/spec/frontend/__helpers__/vue_test_utils_helper_spec.js index dfe5a483223..3bb228f94b8 100644 --- a/spec/frontend/__helpers__/vue_test_utils_helper_spec.js +++ b/spec/frontend/__helpers__/vue_test_utils_helper_spec.js @@ -4,6 +4,7 @@ import { shallowMount, Wrapper as VTUWrapper, WrapperArray as VTUWrapperArray, + ErrorWrapper as VTUErrorWrapper, } from '@vue/test-utils'; import { extendedWrapper, @@ -195,7 +196,7 @@ describe('Vue test utils helpers', () => { }); it('returns a VTU error wrapper', () => { - expect(wrapper[findMethod](text, options).exists()).toBe(false); + expect(wrapper[findMethod](text, options)).toBeInstanceOf(VTUErrorWrapper); }); }); }); diff --git a/spec/frontend/ide/components/repo_editor_spec.js b/spec/frontend/ide/components/repo_editor_spec.js index 646e51160d8..41a93c7ba5a 100644 --- a/spec/frontend/ide/components/repo_editor_spec.js +++ b/spec/frontend/ide/components/repo_editor_spec.js @@ -656,7 +656,7 @@ describe('RepoEditor', () => { }); it("does not add file to state or set markdown image syntax if the file isn't markdown", async () => { - wrapper.setProps({ + await wrapper.setProps({ file: setFileName('myfile.txt'), }); pasteImage(); diff --git a/spec/frontend/notes/components/discussion_actions_spec.js b/spec/frontend/notes/components/discussion_actions_spec.js index c6a7d7ead98..925dbcc09ec 100644 --- a/spec/frontend/notes/components/discussion_actions_spec.js +++ b/spec/frontend/notes/components/discussion_actions_spec.js @@ -20,7 +20,7 @@ const createUnallowedNote = () => describe('DiscussionActions', () => { let wrapper; - const createComponentFactory = (shallow = true) => (props) => { + const createComponentFactory = (shallow = true) => (props, options) => { const store = createStore(); const mountFn = shallow ? shallowMount : mount; @@ -34,6 +34,7 @@ describe('DiscussionActions', () => { shouldShowJumpToNextDiscussion: true, ...props, }, + ...options, }); }; @@ -90,17 +91,17 @@ describe('DiscussionActions', () => { describe('events handling', () => { const createComponent = createComponentFactory(false); - beforeEach(() => { - createComponent(); - }); - it('emits showReplyForm event when clicking on reply placeholder', () => { + createComponent({}, { attachTo: document.body }); + jest.spyOn(wrapper.vm, '$emit'); wrapper.find(ReplyPlaceholder).find('textarea').trigger('focus'); expect(wrapper.vm.$emit).toHaveBeenCalledWith('showReplyForm'); }); it('emits resolve event when clicking on resolve button', () => { + createComponent(); + jest.spyOn(wrapper.vm, '$emit'); wrapper.find(ResolveDiscussionButton).find('button').trigger('click'); expect(wrapper.vm.$emit).toHaveBeenCalledWith('resolve'); diff --git a/spec/frontend/notes/components/discussion_reply_placeholder_spec.js b/spec/frontend/notes/components/discussion_reply_placeholder_spec.js index 2a4cd0df0c7..3932f818c4e 100644 --- a/spec/frontend/notes/components/discussion_reply_placeholder_spec.js +++ b/spec/frontend/notes/components/discussion_reply_placeholder_spec.js @@ -6,31 +6,34 @@ const placeholderText = 'Test Button Text'; describe('ReplyPlaceholder', () => { let wrapper; - const findTextarea = () => wrapper.find({ ref: 'textarea' }); - - beforeEach(() => { + const createComponent = ({ options = {} } = {}) => { wrapper = shallowMount(ReplyPlaceholder, { propsData: { placeholderText, }, + ...options, }); - }); + }; + + const findTextarea = () => wrapper.find({ ref: 'textarea' }); afterEach(() => { wrapper.destroy(); }); - it('emits focus event on button click', () => { - findTextarea().trigger('focus'); + it('emits focus event on button click', async () => { + createComponent({ options: { attachTo: document.body } }); + + await findTextarea().trigger('focus'); - return wrapper.vm.$nextTick().then(() => { - expect(wrapper.emitted()).toEqual({ - focus: [[]], - }); + expect(wrapper.emitted()).toEqual({ + focus: [[]], }); }); it('should render reply button', () => { + createComponent(); + expect(findTextarea().attributes('placeholder')).toEqual(placeholderText); }); }); diff --git a/spec/frontend/pages/projects/graphs/__snapshots__/code_coverage_spec.js.snap b/spec/frontend/pages/projects/graphs/__snapshots__/code_coverage_spec.js.snap index c4c48ea7517..4ba9120d196 100644 --- a/spec/frontend/pages/projects/graphs/__snapshots__/code_coverage_spec.js.snap +++ b/spec/frontend/pages/projects/graphs/__snapshots__/code_coverage_spec.js.snap @@ -66,7 +66,7 @@ exports[`Code Coverage when fetching data is successful matches the snapshot 1`] <gl-area-chart-stub annotations="" data="[object Object]" - formattooltiptext="function () { [native code] }" + formattooltiptext="[Function]" height="200" includelegendavgmax="true" legendaveragetext="Avg" diff --git a/spec/lib/peek/views/memory_spec.rb b/spec/lib/peek/views/memory_spec.rb new file mode 100644 index 00000000000..1f88aadfc54 --- /dev/null +++ b/spec/lib/peek/views/memory_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Peek::Views::Memory, :request_store do + subject! { described_class.new } + + before do + stub_memory_instrumentation + end + + context 'with process_action.action_controller notification' do + it 'returns empty results when it has not yet fired' do + expect(subject.results).to eq({}) + end + + it 'returns memory instrumentation data when it has fired' do + publish_notification + + expect(subject.results[:calls]).to eq('2 MB') + expect(subject.results[:details]).to all(have_key(:item_header)) + expect(subject.results[:details]).to all(have_key(:item_content)) + expect(subject.results[:summary]).to include('Objects allocated' => '200 k') + expect(subject.results[:summary]).to include('Allocator calls' => '500') + expect(subject.results[:summary]).to include('Large allocations' => '1 KB') + end + end + + def stub_memory_instrumentation + start_memory = { + total_malloc_bytes: 1, + total_mallocs: 2, + total_allocated_objects: 3 + } + allow(Gitlab::Memory::Instrumentation).to receive(:start_thread_memory_allocations).and_return(start_memory) + allow(Gitlab::Memory::Instrumentation).to receive(:measure_thread_memory_allocations).with(start_memory).and_return({ + mem_total_bytes: 2_097_152, + mem_bytes: 1024, + mem_mallocs: 500, + mem_objects: 200_000 + }) + Gitlab::InstrumentationHelper.init_instrumentation_data + end + + def publish_notification + headers = double + allow(headers).to receive(:env).and_return('action_dispatch.request_id': 'req-42') + + ActiveSupport::Notifications.publish( + 'process_action.action_controller', Time.current - 1.second, Time.current, 'id', headers: headers + ) + end +end |