Skip to content

Commit

Permalink
Mock formatDateString util function to avoid mismatch between local a…
Browse files Browse the repository at this point in the history
…nd CI test environments
  • Loading branch information
rileyjbauer committed Jan 14, 2019
1 parent 743dd50 commit 25e1b81
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
5 changes: 5 additions & 0 deletions frontend/src/pages/ExperimentList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as React from 'react';
import * as Utils from '../lib/Utils';
import ExperimentList from './ExperimentList';
import TestUtils from '../TestUtils';
import { ApiResourceType } from '../apis/run';
Expand All @@ -34,6 +35,9 @@ describe('ExperimentList', () => {
const historyPushSpy = jest.fn();
const listExperimentsSpy = jest.spyOn(Apis.experimentServiceApi, 'listExperiment');
const listRunsSpy = jest.spyOn(Apis.runServiceApi, 'listRuns');
// We mock this because it uses toLocaleDateString, which causes mismatches between local and CI
// test enviroments
const formatDateStringSpy = jest.spyOn(Utils, 'formatDateString');

function generateProps(): PageProps {
return {
Expand Down Expand Up @@ -71,6 +75,7 @@ describe('ExperimentList', () => {
updateToolbarSpy.mockReset();
listExperimentsSpy.mockReset();
listRunsSpy.mockReset();
formatDateStringSpy.mockImplementation(() => '1/2/2019, 12:34:56 PM');
});

it('renders an empty list with empty state message', () => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/pages/RunDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as React from 'react';
import * as Utils from '../lib/Utils';
import RunDetails from './RunDetails';
import TestUtils from '../TestUtils';
import WorkflowParser from '../lib/WorkflowParser';
Expand All @@ -39,6 +40,9 @@ describe('RunDetails', () => {
const pathsParser = jest.spyOn(WorkflowParser, 'loadNodeOutputPaths');
const pathsWithStepsParser = jest.spyOn(WorkflowParser, 'loadAllOutputPathsWithStepNames');
const loaderSpy = jest.spyOn(OutputArtifactLoader, 'load');
// We mock this because it uses toLocaleDateString, which causes mismatches between local and CI
// test enviroments
const formatDateStringSpy = jest.spyOn(Utils, 'formatDateString');

let testRun: ApiRunDetail = {};
let tree: ShallowWrapper;
Expand Down Expand Up @@ -84,6 +88,7 @@ describe('RunDetails', () => {
pathsParser.mockImplementation(() => []);
pathsWithStepsParser.mockImplementation(() => []);
loaderSpy.mockImplementation(() => Promise.resolve([]));
formatDateStringSpy.mockImplementation(() => '1/2/2019, 12:34:56 PM');
jest.clearAllMocks();
});

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/pages/RunList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as React from 'react';
import * as Utils from '../lib/Utils';
import RunList, { RunListProps } from './RunList';
import TestUtils from '../TestUtils';
import produce from 'immer';
Expand All @@ -37,6 +38,9 @@ describe('RunList', () => {
const getRunSpy = jest.spyOn(Apis.runServiceApi, 'getRun');
const getPipelineSpy = jest.spyOn(Apis.pipelineServiceApi, 'getPipeline');
const getExperimentSpy = jest.spyOn(Apis.experimentServiceApi, 'getExperiment');
// We mock this because it uses toLocaleDateString, which causes mismatches between local and CI
// test enviroments
const formatDateStringSpy = jest.spyOn(Utils, 'formatDateString');

function generateProps(): RunListProps {
return {
Expand Down Expand Up @@ -69,6 +73,9 @@ describe('RunList', () => {
}

beforeEach(() => {
formatDateStringSpy.mockImplementation((date?: Date) => {
return date ? '1/2/2019, 12:34:56 PM' : '-';
});
onErrorSpy.mockClear();
listRunsSpy.mockClear();
getRunSpy.mockClear();
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/pages/Status.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
* limitations under the License.
*/

import * as Utils from '../lib/Utils';
import { shallow } from 'enzyme';
import { statusToIcon, NodePhase } from './Status';


describe('Status', () => {
const startDate = new Date('Wed Jan 9 2019 13:23:22 GMT-0800');
const endDate = new Date('Fri Jan 11 2019 15:36:01 GMT-0800');
// We mock this because it uses toLocaleDateString, which causes mismatches between local and CI
// test enviroments
const formatDateStringSpy = jest.spyOn(Utils, 'formatDateString');

const startDate = new Date('Wed Jan 2 2019 9:10:11 GMT-0800');
const endDate = new Date('Thu Jan 3 2019 10:11:12 GMT-0800');

beforeEach(() => {
formatDateStringSpy.mockImplementation((date: Date) => {
return (date === startDate) ? '1/2/2019, 9:10:11 AM' : '1/3/2019, 10:11:12 AM';
});
});

it('handles an unknown phase', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => null);
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/pages/__snapshots__/RunDetails.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ exports[`RunDetails keeps side pane open and on same tab when run status changes
</div>
<div>
Start:
9/5/2018, 4:03:02 AM
1/2/2019, 12:34:56 PM
</div>
</div>
}
Expand Down Expand Up @@ -324,7 +324,7 @@ exports[`RunDetails keeps side pane open and on same tab when run status changes
</div>
<div>
Start:
9/5/2018, 4:03:02 AM
1/2/2019, 12:34:56 PM
</div>
</div>
}
Expand Down Expand Up @@ -1017,7 +1017,7 @@ exports[`RunDetails shows failure run status in page title 1`] = `
</div>
<div>
Start:
9/5/2018, 4:03:02 AM
1/2/2019, 12:34:56 PM
</div>
</div>
}
Expand Down Expand Up @@ -1089,15 +1089,15 @@ exports[`RunDetails shows run config fields - handles no description 1`] = `
],
Array [
"Created at",
"7/5/2018, 4:03:02 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Started at",
"7/5/2018, 4:03:02 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Finished at",
"7/6/2018, 5:04:03 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Duration",
Expand Down Expand Up @@ -1154,11 +1154,11 @@ exports[`RunDetails shows run config fields - handles no metadata 1`] = `
],
Array [
"Started at",
"7/5/2018, 4:03:02 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Finished at",
"7/6/2018, 5:04:03 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Duration",
Expand Down Expand Up @@ -1211,15 +1211,15 @@ exports[`RunDetails shows run config fields 1`] = `
],
Array [
"Created at",
"7/5/2018, 4:03:02 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Started at",
"7/5/2018, 4:03:02 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Finished at",
"7/6/2018, 5:04:03 AM",
"1/2/2019, 12:34:56 PM",
],
Array [
"Duration",
Expand Down Expand Up @@ -1264,7 +1264,7 @@ exports[`RunDetails shows success run status in page title 1`] = `
</div>
<div>
Start:
9/5/2018, 4:03:02 AM
1/2/2019, 12:34:56 PM
</div>
</div>
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/__snapshots__/Status.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ exports[`Status displays start and end dates if both are provided 1`] = `
</div>
<div>
Start:
1/9/2019, 1:23:22 PM
1/2/2019, 9:10:11 AM
</div>
<div>
End:
1/11/2019, 3:36:01 PM
1/3/2019, 10:11:12 AM
</div>
</div>
}
Expand Down Expand Up @@ -815,7 +815,7 @@ exports[`Status does not display a end date if none was provided 1`] = `
</div>
<div>
Start:
1/9/2019, 1:23:22 PM
1/2/2019, 9:10:11 AM
</div>
</div>
}
Expand Down Expand Up @@ -1233,7 +1233,7 @@ exports[`Status does not display a start date if none was provided 1`] = `
</div>
<div>
End:
1/11/2019, 3:36:01 PM
1/3/2019, 10:11:12 AM
</div>
</div>
}
Expand Down

0 comments on commit 25e1b81

Please sign in to comment.