Closed frostiebot closed 7 years ago
Hello @frostiebot, you can use USER root
directive to get elevated privileges, and then use USER user
to swtich them back. Also /root/
directory is missing in the container's file system, it must be created, e.g.:
FROM testcafe/testcafe
USER root
RUN mkdir /root && cd /opt/testcafe && npm install testcafe-vue-selectors
USER user
I had the similar problem.
When trying @AndreyBelym answer I had an error Can not find 'testcafe-vue-selectors'
.
This solved it:
FROM testcafe/testcafe
USER root
ENV NODE_PATH=/opt:/opt/testcafe/node_modules
# Installing custom dependencies:
RUN cd /opt/testcafe && npm install \
testcafe-nuxt-selectors testcafe-vue-selectors
USER user
Link to the source: https://github.com/wemake-services/wemake-vue-template/blob/master/template/docker/testcafe/Dockerfile
@sobolevn, you're right, in this case NODE_PATH
should be configured to include Node.js modules from /opt/testcafe
.
I had to slightly edit @sobolevn solution to add the /usr/lib/node_modules
to NODE_PATH
. If not, I was running in the following error :
ERROR Cannot prepare tests due to an error.
Error: Cannot find module 'testcafe'
at Object.<anonymous> (/opt/testcafe/node_modules/testcafe-react-selectors/lib/index.js:8:17)
at Object.origExt [as .js] (/usr/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:76:21)
at Object.<anonymous> (/tests/homepage.test.js:2:1)
at Function._compile [as _execAsModule] (/usr/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
at ESNextTestFileCompiler._execAsModule [as compile] (/usr/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:144:42)
at compile (/usr/lib/node_modules/testcafe/src/compiler/index.js:50:42)
My resulting Dockerfile is the following :
FROM testcafe/testcafe
USER root
ENV NODE_PATH=/opt:/usr/lib/node_modules:/opt/testcafe/node_modules
# Installing custom dependencies:
RUN cd /opt/testcafe && npm install \
testcafe-react-selectors
USER user
Hi, my Dockerfile looks following:
FROM testcafe/testcafe
USER root
ENV NODE_PATH=/opt:/usr/lib/node_modules:/opt/testcafe/node_modules
RUN cd /opt/testcafe && npm install \
tsyringe@3.2.0 testcafe-reporter-html@1.4.4
USER user
Which is basically the same as mentioned above, but still get:
/tests/pages/LoginPage.ts (1, 30): Cannot find module 'tsyringe'.
However, when I delete testcafe-reporter-html
from dependencies, the TestCafe does not start and complain about missing HTML reporter. This package is clearly visible, while tsyringe
is not.
Do you have any ideas why it's not working?
The TypeScript compiler ignores the NODE_PATH
variable when searching for modules. Add tsyringe
as a dependency to your test project instead of installing it in the TestCafe directory.
Hello @frostiebot, you can use
USER root
directive to get elevated privileges, and then useUSER user
to swtich them back. Also/root/
directory is missing in the container's file system, it must be created, e.g.:FROM testcafe/testcafe USER root RUN mkdir /root && cd /opt/testcafe && npm install testcafe-vue-selectors USER user
if i want to install all dependecies from my package.json how that will be?
RUN cd /opt/testcafe && npm install
with this is enough?
@lgriotti The cd
command should change the current directory to the directory containing your package.json
.
I am curious if there is any way to include this library when running testcafe from within docker?
I have attempted to create a new docker image based off
testcafe/testcafe
, but ran into permissions-related issues when attempting to install testcafe-react-selectors via npm from within my new Dockerfile.Another approach I made that I really am not entirely keen on involved essentially copying the Dockerfile from the testcafe github and adding multiple steps to basically
ADD
the testcafe release tar.gz, install gulp, build testcafe, copy the required directories to /opt/testcafe within the image and then finally install testcafe-react-selectors seperately. Not fun.It's entirely possible I'm missing something amazingly simple, but I would appreciate any advice you could give about being able to completely contain both testcafe and this library within a single-entrypoint docker image.
Thanks!
EDIT - Just to give you an example of the truly horrible hoops I jumped through...