我正在尝试运行执行 jest -t
使用以下 Docker cli 命令的变体:
docker run -it node-jest npx jest -t "This string matches exactly one test"
如果我要运行
npx jest -t "This string matches exactly one test"
,这不会做同样的事情本地。
似乎双引号被剥离/忽略,只有
This
正在传递给
jest -t
.看来
This string matches exactly one test
在空间上被分割并被视为单独的参数。有人可以解释为什么会发生这种情况,以及如何获得
"This string matches exactly one test"
传递给
docker run
正确(希望以一种可读/理智的方式)?
请您参考如下方法:
您没有提到错误,引号似乎很好,它应该可以使用 shell 运行或运行容器,但我的假设是您没有设置 WORKING
Dockerfile 中的目录或 Dockerfile 有问题
这是来自 jest docker imag 的工作示例和一些 testing code .
docker run -ti adiii717/jest sh -c 'npx jest -t "it should filter by a search term (link)"'
输出:
运行所有测试套件,测试匹配“它应该按搜索词(链接)过滤”。
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 12.5 | 0 | 0 | 16.67 | |
filterByTerm.js | 12.5 | 0 | 0 | 16.67 | 2,3,4,5,6 |
-----------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 skipped, 0 of 1 total
Tests: 3 skipped, 3 total
Snapshots: 0 total
Time: 1.109s
Ran all test suites with tests matching "it should filter by a search term (link)".
这是 Dockerfile
FROM node:alpine
RUN apk add --no-cache git
RUN npm install jest npx -g
WORKDIR /app
RUN git clone https://github.com/valentinogagliardi/getting-started-with-jest.git /app
RUN npm install