Commit 0ca7766d authored by Scott Stern's avatar Scott Stern Committed by Mike Greiling

Replace underscore with lodash in ./spec/js

Add babel-lodash for tree shaking
and nice import statements.
parent e8b3d4d1
...@@ -11,7 +11,7 @@ old_notes_spec.js is the spec for the legacy, jQuery notes application. It has n ...@@ -11,7 +11,7 @@ old_notes_spec.js is the spec for the legacy, jQuery notes application. It has n
*/ */
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore'; import { escape, uniqueId } from 'lodash';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import Autosize from 'autosize'; import Autosize from 'autosize';
import 'jquery.caret'; // required by at.js import 'jquery.caret'; // required by at.js
...@@ -1449,7 +1449,7 @@ export default class Notes { ...@@ -1449,7 +1449,7 @@ export default class Notes {
return { return {
// eslint-disable-next-line no-jquery/no-serialize // eslint-disable-next-line no-jquery/no-serialize
formData: $form.serialize(), formData: $form.serialize(),
formContent: _.escape(content), formContent: escape(content),
formAction: $form.attr('action'), formAction: $form.attr('action'),
formContentOriginal: content, formContentOriginal: content,
}; };
...@@ -1516,18 +1516,16 @@ export default class Notes { ...@@ -1516,18 +1516,16 @@ export default class Notes {
`<li id="${uniqueId}" class="note being-posted fade-in-half timeline-entry"> `<li id="${uniqueId}" class="note being-posted fade-in-half timeline-entry">
<div class="timeline-entry-inner"> <div class="timeline-entry-inner">
<div class="timeline-icon"> <div class="timeline-icon">
<a href="/${_.escape(currentUsername)}"> <a href="/${escape(currentUsername)}">
<img class="avatar s40" src="${currentUserAvatar}" /> <img class="avatar s40" src="${currentUserAvatar}" />
</a> </a>
</div> </div>
<div class="timeline-content ${discussionClass}"> <div class="timeline-content ${discussionClass}">
<div class="note-header"> <div class="note-header">
<div class="note-header-info"> <div class="note-header-info">
<a href="/${_.escape(currentUsername)}"> <a href="/${escape(currentUsername)}">
<span class="d-none d-sm-inline-block bold">${_.escape( <span class="d-none d-sm-inline-block bold">${escape(currentUsername)}</span>
currentUsername, <span class="note-headline-light">${escape(currentUsername)}</span>
)}</span>
<span class="note-headline-light">${_.escape(currentUsername)}</span>
</a> </a>
</div> </div>
</div> </div>
...@@ -1541,8 +1539,8 @@ export default class Notes { ...@@ -1541,8 +1539,8 @@ export default class Notes {
</li>`, </li>`,
); );
$tempNote.find('.d-none.d-sm-inline-block').text(_.escape(currentUserFullname)); $tempNote.find('.d-none.d-sm-inline-block').text(escape(currentUserFullname));
$tempNote.find('.note-headline-light').text(`@${_.escape(currentUsername)}`); $tempNote.find('.note-headline-light').text(`@${escape(currentUsername)}`);
return $tempNote; return $tempNote;
} }
...@@ -1627,7 +1625,7 @@ export default class Notes { ...@@ -1627,7 +1625,7 @@ export default class Notes {
// Show placeholder note // Show placeholder note
if (tempFormContent) { if (tempFormContent) {
noteUniqueId = _.uniqueId('tempNote_'); noteUniqueId = uniqueId('tempNote_');
$notesContainer.append( $notesContainer.append(
this.createPlaceholderNote({ this.createPlaceholderNote({
formContent: tempFormContent, formContent: tempFormContent,
...@@ -1642,7 +1640,7 @@ export default class Notes { ...@@ -1642,7 +1640,7 @@ export default class Notes {
// Show placeholder system note // Show placeholder system note
if (hasQuickActions) { if (hasQuickActions) {
systemNoteUniqueId = _.uniqueId('tempSystemNote_'); systemNoteUniqueId = uniqueId('tempSystemNote_');
$notesContainer.append( $notesContainer.append(
this.createPlaceholderSystemNote({ this.createPlaceholderSystemNote({
formContent: this.getQuickActionDescription( formContent: this.getQuickActionDescription(
...@@ -1825,7 +1823,7 @@ export default class Notes { ...@@ -1825,7 +1823,7 @@ export default class Notes {
}) })
.catch(() => { .catch(() => {
// Submission failed, revert back to original note // Submission failed, revert back to original note
$noteBodyText.html(_.escape(cachedNoteBodyText)); $noteBodyText.html(escape(cachedNoteBodyText));
$editingNote.removeClass('being-posted fade-in'); $editingNote.removeClass('being-posted fade-in');
$editingNote.find('.fa.fa-spinner').remove(); $editingNote.find('.fa.fa-spinner').remove();
......
...@@ -22,6 +22,7 @@ const plugins = [ ...@@ -22,6 +22,7 @@ const plugins = [
'@babel/plugin-proposal-json-strings', '@babel/plugin-proposal-json-strings',
'@babel/plugin-proposal-private-methods', '@babel/plugin-proposal-private-methods',
'@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-optional-chaining',
'lodash',
]; ];
// add code coverage tooling if necessary // add code coverage tooling if necessary
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
"aws-sdk": "^2.526.0", "aws-sdk": "^2.526.0",
"axios": "^0.19.0", "axios": "^0.19.0",
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"babel-plugin-lodash": "^3.3.4",
"bootstrap": "4.3.1", "bootstrap": "4.3.1",
"brace-expansion": "^1.1.8", "brace-expansion": "^1.1.8",
"cache-loader": "^4.1.0", "cache-loader": "^4.1.0",
...@@ -94,6 +95,7 @@ ...@@ -94,6 +95,7 @@
"jszip": "^3.1.3", "jszip": "^3.1.3",
"jszip-utils": "^0.0.2", "jszip-utils": "^0.0.2",
"katex": "^0.10.0", "katex": "^0.10.0",
"lodash": "^4.17.15",
"marked": "^0.3.12", "marked": "^0.3.12",
"mermaid": "^8.4.5", "mermaid": "^8.4.5",
"monaco-editor": "^0.18.1", "monaco-editor": "^0.18.1",
......
/* global ListAssignee, ListLabel, ListIssue */ /* global ListAssignee, ListLabel, ListIssue */
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import _ from 'underscore'; import { range } from 'lodash';
import '~/boards/models/label'; import '~/boards/models/label';
import '~/boards/models/assignee'; import '~/boards/models/assignee';
import '~/boards/models/issue'; import '~/boards/models/issue';
...@@ -222,7 +222,7 @@ describe('Issue card component', () => { ...@@ -222,7 +222,7 @@ describe('Issue card component', () => {
it('renders 99+ avatar counter', done => { it('renders 99+ avatar counter', done => {
const assignees = [ const assignees = [
...wrapper.props('issue').assignees, ...wrapper.props('issue').assignees,
..._.range(5, 103).map( ...range(5, 103).map(
i => i =>
new ListAssignee({ new ListAssignee({
id: i, id: i,
......
import _ from 'underscore'; import { pick, clone } from 'lodash';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils'; import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
...@@ -15,7 +15,7 @@ describe('error tracking settings project dropdown', () => { ...@@ -15,7 +15,7 @@ describe('error tracking settings project dropdown', () => {
wrapper = shallowMount(ProjectDropdown, { wrapper = shallowMount(ProjectDropdown, {
localVue, localVue,
propsData: { propsData: {
..._.pick( ...pick(
defaultProps, defaultProps,
'dropdownLabel', 'dropdownLabel',
'invalidProjectLabel', 'invalidProjectLabel',
...@@ -65,7 +65,7 @@ describe('error tracking settings project dropdown', () => { ...@@ -65,7 +65,7 @@ describe('error tracking settings project dropdown', () => {
describe('populated project list', () => { describe('populated project list', () => {
beforeEach(() => { beforeEach(() => {
wrapper.setProps({ projects: _.clone(projectList), hasProjects: true }); wrapper.setProps({ projects: clone(projectList), hasProjects: true });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -82,10 +82,10 @@ describe('error tracking settings project dropdown', () => { ...@@ -82,10 +82,10 @@ describe('error tracking settings project dropdown', () => {
}); });
describe('selected project', () => { describe('selected project', () => {
const selectedProject = _.clone(projectList[0]); const selectedProject = clone(projectList[0]);
beforeEach(() => { beforeEach(() => {
wrapper.setProps({ projects: _.clone(projectList), selectedProject, hasProjects: true }); wrapper.setProps({ projects: clone(projectList), selectedProject, hasProjects: true });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -98,7 +98,7 @@ describe('error tracking settings project dropdown', () => { ...@@ -98,7 +98,7 @@ describe('error tracking settings project dropdown', () => {
describe('invalid project selected', () => { describe('invalid project selected', () => {
beforeEach(() => { beforeEach(() => {
wrapper.setProps({ wrapper.setProps({
projects: _.clone(projectList), projects: clone(projectList),
selectedProject: staleProject, selectedProject: staleProject,
isProjectInvalid: true, isProjectInvalid: true,
}); });
......
/* eslint-disable import/no-commonjs, no-new */ /* eslint-disable import/no-commonjs, no-new */
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import { createSpyObj } from 'helpers/jest_helpers'; import { createSpyObj } from 'helpers/jest_helpers';
...@@ -792,14 +791,11 @@ describe('Old Notes (~/notes.js)', () => { ...@@ -792,14 +791,11 @@ describe('Old Notes (~/notes.js)', () => {
}); });
it('should return form metadata with sanitized formContent from form reference', () => { it('should return form metadata with sanitized formContent from form reference', () => {
jest.spyOn(_, 'escape');
sampleComment = '<script>alert("Boom!");</script>'; sampleComment = '<script>alert("Boom!");</script>';
$form.find('textarea.js-note-text').val(sampleComment); $form.find('textarea.js-note-text').val(sampleComment);
const { formContent } = notes.getFormData($form); const { formContent } = notes.getFormData($form);
expect(_.escape).toHaveBeenCalledWith(sampleComment);
expect(formContent).toEqual('&lt;script&gt;alert(&quot;Boom!&quot;);&lt;/script&gt;'); expect(formContent).toEqual('&lt;script&gt;alert(&quot;Boom!&quot;);&lt;/script&gt;');
}); });
}); });
...@@ -990,7 +986,6 @@ describe('Old Notes (~/notes.js)', () => { ...@@ -990,7 +986,6 @@ describe('Old Notes (~/notes.js)', () => {
beforeEach(() => { beforeEach(() => {
notes = new Notes('', []); notes = new Notes('', []);
jest.spyOn(_, 'escape');
}); });
it('should return constructed placeholder element for system note based on form contents', () => { it('should return constructed placeholder element for system note based on form contents', () => {
......
import _ from 'underscore'; import { each } from 'lodash';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui'; import { GlLink } from '@gitlab/ui';
...@@ -58,7 +58,7 @@ describe('User Avatar Link Component', () => { ...@@ -58,7 +58,7 @@ describe('User Avatar Link Component', () => {
}); });
it('should return necessary props as defined', () => { it('should return necessary props as defined', () => {
_.each(defaultProps, (val, key) => { each(defaultProps, (val, key) => {
expect(wrapper.vm[key]).toBeDefined(); expect(wrapper.vm[key]).toBeDefined();
}); });
}); });
......
...@@ -122,12 +122,12 @@ ...@@ -122,12 +122,12 @@
dependencies: dependencies:
"@babel/types" "^7.5.5" "@babel/types" "^7.5.5"
"@babel/helper-module-imports@^7.0.0": "@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.0.0-beta.49":
version "7.0.0" version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d" resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.8.3.tgz#7fe39589b39c016331b6b8c3f441e8f0b1419498"
integrity sha512-aP/hlLq01DWNEiDg4Jn23i+CXxW/owM4WpDLFUbpjxe4NS3BhLVZQ5i7E0ZrxuQ/vwekIeciyamgB1UIYxxM6A== integrity sha512-R0Bx3jippsbAEtzkpZ/6FIiuzOURPcMjHp+Z6xPe6DtApDJx+w7UYyOLanZqO8+wKR9G10s/FmHXvxaMd9s6Kg==
dependencies: dependencies:
"@babel/types" "^7.0.0" "@babel/types" "^7.8.3"
"@babel/helper-module-transforms@^7.1.0", "@babel/helper-module-transforms@^7.4.4": "@babel/helper-module-transforms@^7.1.0", "@babel/helper-module-transforms@^7.4.4":
version "7.5.5" version "7.5.5"
...@@ -683,10 +683,10 @@ ...@@ -683,10 +683,10 @@
globals "^11.1.0" globals "^11.1.0"
lodash "^4.17.13" lodash "^4.17.13"
"@babel/types@^7.0.0", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.5.5", "@babel/types@^7.6.0": "@babel/types@^7.0.0", "@babel/types@^7.0.0-beta.49", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.5.5", "@babel/types@^7.6.0", "@babel/types@^7.8.3":
version "7.6.1" version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.6.1.tgz#53abf3308add3ac2a2884d539151c57c4b3ac648" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.8.3.tgz#5a383dffa5416db1b73dedffd311ffd0788fb31c"
integrity sha512-X7gdiuaCmA0uRjCmRtYJNAVCc/q+5xSgsfKJHqMN4iNLILX39677fJE1O40arPMh0TTtS9ItH67yre6c7k6t0g== integrity sha512-jBD+G8+LWpMBBWvVcdr4QysjUE4mU/syrhN17o1u3gx0/WzJB1kwiVZAXRtWbsIPOwW8pF/YJV5+nmetPzepXg==
dependencies: dependencies:
esutils "^2.0.2" esutils "^2.0.2"
lodash "^4.17.13" lodash "^4.17.13"
...@@ -1890,6 +1890,17 @@ babel-plugin-jest-hoist@^24.6.0: ...@@ -1890,6 +1890,17 @@ babel-plugin-jest-hoist@^24.6.0:
dependencies: dependencies:
"@types/babel__traverse" "^7.0.6" "@types/babel__traverse" "^7.0.6"
babel-plugin-lodash@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
integrity sha512-yDZLjK7TCkWl1gpBeBGmuaDIFhZKmkoL+Cu2MUUjv5VxUZx/z7tBGBCBcQs5RI1Bkz5LLmNdjx7paOyQtMovyg==
dependencies:
"@babel/helper-module-imports" "^7.0.0-beta.49"
"@babel/types" "^7.0.0-beta.49"
glob "^7.1.1"
lodash "^4.17.10"
require-package-name "^2.0.1"
babel-plugin-rewire@^1.2.0: babel-plugin-rewire@^1.2.0:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-rewire/-/babel-plugin-rewire-1.2.0.tgz#822562d72ed2c84e47c0f95ee232c920853e9d89" resolved "https://registry.yarnpkg.com/babel-plugin-rewire/-/babel-plugin-rewire-1.2.0.tgz#822562d72ed2c84e47c0f95ee232c920853e9d89"
...@@ -9725,6 +9736,11 @@ require-main-filename@^2.0.0: ...@@ -9725,6 +9736,11 @@ require-main-filename@^2.0.0:
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
require-package-name@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/require-package-name/-/require-package-name-2.0.1.tgz#c11e97276b65b8e2923f75dabf5fb2ef0c3841b9"
integrity sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk=
require-uncached@^1.0.3: require-uncached@^1.0.3:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3"
......
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