我有一个具有如下功能的文件:
export async function loginNextAuth(displayName, password) {
const response = await fetch('/api/auth/callback/credentials')
}
Run Code Online (Sandbox Code Playgroud)
请注意,没有导入,这是全局命名空间中的内置 Node.js 获取函数。这在剧作家测试和常规代码中效果很好。
由于某种原因,在 Jest 测试中运行时global和globalThis都不具有该fetch属性。这会导致笑话错误,指出该fetch变量未声明。
jest 测试中返回的结果process.version与我在开发中使用的 Node 版本相同。
这是一个类似的 SO 问题,但是 OP 正在使用从模块导入的外部获取函数。
更新:节点版本为v18.12.1
有问题的错误:
const response = await fetch("/api/auth/callback/credentials", {
^
ReferenceError: fetch is not defined
at Object.loginNextAuth (web_app/lib/tests/jest/login.js:8:22)
at loginAs (web_app/pages/permissions.jest.js:22:71)
Run Code Online (Sandbox Code Playgroud) 每次我构建容器时,我都必须等待apk add docker完成,这需要很长时间。由于每次下载相同的内容时,我是否可以以某种方式强制 Docker 缓存 apk 的下载以用于开发目的?
这是我的 Dockerfile:
FROM golang:1.13.5-alpine
WORKDIR /go/src/app
COPY src .
RUN go get -d -v ./...
RUN go install -v ./...
RUN apk add --update docker
CMD ["app"]
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我用这部分volumes: - /var/run/docker.sock:/var/run/docker.sock我docker-compose.yml,如果该事项使用兄弟容器。
编辑:我发现谷歌docker.tgz 在 Chromium 中复制:
# add docker client -- do not install docker via apk -- it will try to install
# docker engine which takes a lot of space as well (we don't need …Run Code Online (Sandbox Code Playgroud) 我有一个 API POST 端点创建一个资源,该资源可能有多个关系。为了确保首先使用有效关系创建资源,我需要检查给定的 ID 是否存在。有多个这样的关系,我不想依次等待每个关系。这是我的代码:
[HttpPost]
public async Task<ActionResult<Person>> PostPerson(Person person)
{
ValueTask<Person> master, apprentice;
ValueTask<Planet> planet;
ValueTask<Models.LifeFormType> lifeFormType;
if (person.MasterId.HasValue)
{
master = _context.People.FindAsync(person.MasterId);
}
if (person.ApprenticeId.HasValue)
{
apprentice = _context.People.FindAsync(person.ApprenticeId);
}
if (person.FromPlanetId.HasValue)
{
planet = _context.Planets.FindAsync(person.FromPlanetId);
}
if (person.LFTypeId.HasValue)
{
lifeFormType = _context.LifeFormTypes.FindAsync(person.LFTypeId);
}
List<ValueTask> tasks = new List<ValueTask> {master, apprentice, planet, lifeFormType};
// if the above worked I'd process the tasks as they completed and throw errors
// if the given id was not found …Run Code Online (Sandbox Code Playgroud) alpine-linux ×1
async-await ×1
c# ×1
docker ×1
dockerfile ×1
fetch ×1
javascript ×1
jestjs ×1
node.js ×1
task ×1