2

I am using docker slaves for build via Docker plugin for jenkins. I have no issues with my builds but however in one repository we're passing TZ variable to jest as shown below for a particular test suite. That variable is not taking effect and causes to fail the test.

> @different/different-ui@1.6.0 test /home/jenkins/agent/workspace/ferent_CI_wtml_25hf0e_for_mahela
> TZ=Australia/Sydney jest --config jest.config.js

Test fails as shown below

PASS src/components/data-molecule/data-molecule.spec.tsx
PASS src/components/button/button.spec.tsx
PASS src/components/text-box/text-box.spec.tsx
PASS src/utils/cascade.spec.tsx
PASS src/components/widget/widget.spec.tsx
PASS src/components/clickable/clickable.spec.tsx
PASS src/components/tag/tag.spec.tsx
FAIL src/components/table-cell-date-value/table-cell-date-value.spec.tsx
  ��� <TableCellDateValue /> ��� cell convert the provided date time value correctly

    Expected value   "Aug 1, 2019 - 12:55 pm"
    Received:
      "Aug 1, 2019 - 2:55 am"

    Message:
      expected <TableCellDateValue /> to have text 'Aug 1, 2019 - 12:55 pm', but it has 'Aug 1, 2019 - 2:55 am'      
         
         HTML:
         
         <span id={[undefined]} className={[undefined]}>Aug 1, 2019 - 2:55 am</span>

    Difference:

    - Expected
    + Received

    - Aug 1, 2019 - 12:55 pm
    + Aug 1, 2019 - 2:55 am

I have tried few things to overcome this

  1. tried to set timezone as given below How do I set a timezone in my Jest config?

  2. Tried to export env variable TZ in bash_profile in docker file itself

RUN ["/bin/bash", "-c", "echo 'export TZ=Australia/Sydney' >> ~/.bash_profile"]

I'm not sure whether docker plugin uses an interactive shell or a non-interactive shell while connecting to the container.

So far all of these efforts were unsuccessful.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Mahela Wickramasekara
  • 603
  • 1
  • 11
  • 22
  • 1
    Hope this helps [TimeZone in dockerfile](https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes) – chris Feb 16 '20 at 04:40
  • @chris yes this really helped a lot. now I can get the value to the env variable. I can even print the value but some how the shell that executes the test not getting it :( – Mahela Wickramasekara Feb 16 '20 at 14:30
  • @MahelaWickramasekara did you try passing the variable to the container with ```-e``` Also, try to echo the variable name i.e. ```echo $TZ``` – Anuradha Fernando Feb 25 '20 at 04:39
  • @AnuradhaFernando not exactly similar way. we can set the TZ env variable in may different ways. eg: can set it with ENV in the dockerfile iteself(https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes) can even echo it in the pipeline but npm doesn't get it when I run npm test – Mahela Wickramasekara Feb 25 '20 at 09:34
  • I have posted an answer for similar issue, hope that helps. https://stackoverflow.com/a/76818587/4583071 – Ashwaq Aug 02 '23 at 09:40

0 Answers0