我正在尝试升级我的 api 以使用 node-fetch 3.0.0。他们的文档中的部分重大更改是,node-fetch 现在是一个纯粹的 ESM 模块。
\nhttps://github.com/node-fetch/node-fetch/blob/main/docs/CHANGELOG.md
\n我的单元测试已经开始突破这个变化。我使用 jest.requireActual("node-fetch") 作为 Response 对象
\nconst { Response } = jest.requireActual("node-fetch");\nRun Code Online (Sandbox Code Playgroud)\n然而,随着新的变化,我得到:
\n“类型 \'{}\' 上不存在属性 \'Response\'。”
\n我尝试更改为 import 语句,这似乎可以修复该错误:
\nimport { Response } from "node-fetch"\nRun Code Online (Sandbox Code Playgroud)\n现在,当我运行单元测试时,出现以下错误:
\nTest suite failed to run\n \n Jest encountered an unexpected token \n \n This usually means that you are trying to import a file which Jest cannot parse, e.g. it\'s not plain JavaScript. \n \n By …Run Code Online (Sandbox Code Playgroud) 我正在制作一款国际象棋游戏,并使用 Vue 3 和 TypeScript 以及 Pinia 进行状态管理。
我想做如下的事情:
export const useStore = defineStore("game", {
state: () => {
return {
moves: [],
gameBoard: getInitialBoard(),
playerTurn: PieceColor.White,
previousPieceSelected: undefined
}
},
updatePreviousPieceSelected(piece: Piece | undefined ) {
this.previousPieceSelected = piece
}
}
})
Run Code Online (Sandbox Code Playgroud)
更新游戏状态.vue
setup() {
const store = useStore()
const previousPieceSelected: Piece | undefined = store.previousPieceSelected;
let playerTurn: PieceColor = store.playerTurn;
const initialGameState: GameState = {
boardState: store.gameBoard,
playerTurn,
};
const updateGameState = (
cellRow: number,
cellCol: number,
currentPiece: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Vue3,其中很多对象都是用于反应性的代理对象。我想创建代理对象之一和最近发现的 StructuredClone 的深层副本。
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
当我运行以下代码时,在 proxyObj 上执行 StructuredClone 时出现错误:
const obj = {
name: "Steve",
age: 50
}
const handler = {}
const proxyObj = new Proxy(obj, {})
console.log(proxyObj)
const objCopy = structuredClone(obj)
console.log(objCopy)
const proxyObjCopy = structuredClone(proxyObj)
console.log(objCopy)
Run Code Online (Sandbox Code Playgroud)
未捕获的 DOMException:无法在“窗口”上执行“structedClone”:# 无法克隆。
有没有办法克隆代理对象?有没有办法我可以先取消引用它,复制它,而不失去反应性?任何帮助表示赞赏!
我尝试了以下操作: https://github.com/visualfanatic/vue-svg-loader/tree/master
但与 vue-template-compiler 存在版本冲突,因为它在 Vue 2 中使用。
我尝试过: https: //github.com/visualfanatic/vue-svg-loader
但我缺少一个特定的 vue 依赖项。
我注意到使用打字稿有一个警告,您需要声明类型定义文件。但是,我仍然得到“找不到模块 '../../assets/myLogo.svg' 或其相应的类型声明”。
这是我添加的内容:
vue.config.js
module.exports = {
chainWebpack: (config) =>
{
const svgRule = config.module.rule('svg');
svgRule.uses.clear();
svgRule
.use('vue-loader-v16')
.loader('vue-loader-v16')
.end()
.use('vue-svg-loader')
.loader('vue-svg-loader');
},
configureWebpack: process.env.NODE_ENV === 'production' ? {} : {
devtool: 'source-map'
},
publicPath: process.env.NODE_ENV === 'production' ?
'/PersonalWebsite/' : '/'
}
Run Code Online (Sandbox Code Playgroud)
垫片-svg.d.ts
declare module '*.svg' {
const content: any;
export default content;
}
Run Code Online (Sandbox Code Playgroud)
我的组件.vue
<template>
<div>
<MyLogo />
</div>
</template>
<script lang="ts">
import …Run Code Online (Sandbox Code Playgroud) 我正在尝试用 jest 来模拟我的 azure 函数的节点获取。在测试中我有以下内容:
索引.test.ts
jest.mock("node-fetch");
import fetch from "node-fetch";
const {Response} = jest.requireActual("node-fetch");
// Setup code here...
const expectedResult: User = {
user_id: "1",
email: "testEmail@email.com",
name: "testUser",
nickname: "test",
picture: "pic",
app_metadata: {
email: "testEmail@email.com"
}
};
(fetch as jest.MockedFunction<typeof fetch>).mockReturnValue(new Response(JSON.stringify(expectedResult)));
Run Code Online (Sandbox Code Playgroud)
当我调用它时,我正在执行以下操作:
索引.ts
const options = {
method: 'PATCH',
headers: { "Content-Type": 'application/json', authorization: `Bearer ${accessToken}`},
body: body
};
const userResponse = await fetch(usersEndpoint, options);
const jsonResult = await userResponse.json();
context.res = {
body: jsonResult
}; …Run Code Online (Sandbox Code Playgroud) 我是 powershell 新手,我希望创建一个 powershell 脚本来使用两个不同版本的 Visual Studio 打开两个不同的解决方案文件。我有打开不同 Visual Studio 版本的命令,但不确定如何打开每个版本的解决方案。这是我到目前为止所拥有的。
$vs19 = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe"
$vs19WorkDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\"
$vs15 = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe"
$vs15WorkDir = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\"
Start-Process $vs19 -WorkingDirectory $vs19WorkDir
Start-Process $vs15 -WorkingDirectory $vs15WorkDir
Run Code Online (Sandbox Code Playgroud) 我是反应测试库的新手,所以这可能很容易,但我目前有一个从流畅的 UI 导入的下拉列表,当我尝试测试它时,当前收到“该元素没有值设置器”错误使用 React 测试库。这是我的渲染函数。
import { Dropdown, IDropdownStyles, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import { Stack } from 'office-ui-fabric-react/lib/Stack';
render()
{
return (
<div className="LandingPage">
<h3>Here are some options</h3>
<form onSubmit={this.handleSubmit}>
<Stack>
<Stack.Item align="center">
<Dropdown
placeholder="Select an option"
label="Select an option"
options={this.options}
styles={this.dropdownStyles}
onChange={this.handleChange}
data-testid="myId"
/>
</Stack.Item>
</Stack>
</form>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是失败的行:
const dropdownOption: IDropdownOption = {
key: "0",
text: "dropdownOption"
}
fireEvent.click(queryByTestId("myId"), { target: { value: 'B' }, option: dropdownOption })
Run Code Online (Sandbox Code Playgroud)
The given element does not have …Run Code Online (Sandbox Code Playgroud) 我正在向我的 asp.net core 应用程序添加一个 dockerfile,它位于一个子目录中。我正在尝试创建一个 github 操作来运行 dockerfile,但该操作很难找到它。我的文件夹结构是:
api/
|--Data/
|--Service/
|--|--Dockerfile
|--Tests/
|--MyProject.sln
frontend/
Run Code Online (Sandbox Code Playgroud)
我的action.yml是:
name: Docker Image CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
Run Code Online (Sandbox Code Playgroud)
当操作运行时,我在 docker 构建上收到以下错误。
Run docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
shell: /bin/bash -e {0}
unable to …Run Code Online (Sandbox Code Playgroud) 我在 azure 函数中定义了一个 api,我想以可以生成 openAPI 规范的方式对其进行注释。
我尝试过使用 tsoa,但它似乎与无服务器不兼容。目前,openAPI 规范是使用 swagger-jsdoc 生成的,但在注释中包含描述符是不可维护的。我想要类似于 .NET 端 swagger 的工作方式,其中我可以使用路由信息注释函数,并且库将生成 openAPI 规范。这对于打字稿存在吗?我还查看了 Azure 的 API 管理来生成规范,但这些函数目前不是函数应用程序的一部分(它们作为静态站点 api 的一部分部署),并且我不确定 api 管理是否能够处理打字稿类型。
这是我当前使用 swagger-jsdoc 定义规范的设置示例。
/**
* @swagger
* /api/user:
* get:
* tags:
* - user
* summary: Get the user by Id
* description: "Returns a single user"
* parameters:
* - in: "query"
* name: "id"
* description: "ID of the user to return"
* required: true
* schema:
* type: "string"
* responses: …Run Code Online (Sandbox Code Playgroud) 我目前有两个无限异步任务正在运行,并且希望在它们之间共享状态。一项任务是读取消息然后发送消息的 WebSocket 连接,另一项任务读取传入的光数据。我想在两个任务之间发送一个布尔值,表明 websocket 连接是否成功。
这是我初始化上下文的方式。
client_connect_var = contextvars.ContextVar('client_connect',default = False)
client_connect_var.set(False)
ctx = contextvars.copy_context()
async def main():
message = json.dumps({'payload': {
'payload'})
loop = asyncio.get_event_loop()
start_light = asyncio.create_task(calculate_idle(3))
await asyncio.gather(init_connection(message), start_light)
ctx.run(asyncio.run(main()))
Run Code Online (Sandbox Code Playgroud)
这是我的 init_connection 中的代码:
async def init_connection(message):
async with websockets.connect(uri) as websocket:
#This should set the global context variable to true
client_connect_var.set(True)
CLIENT_WS = websocket
client_connect = client_connect_var.get()
# send init message
await websocket.send(message)
print("Connection is open")
while client_connect:
await handleMessages(websocket, message)
await websocket.close()
Run Code Online (Sandbox Code Playgroud)
这是它试图获取灯光代码中当前状态的地方
async def calculate_idle(t): …Run Code Online (Sandbox Code Playgroud) 我是 Azure Dev Ops 的新手,我正在尝试为我的项目创建管道。该项目最初是在 subversion 中,并且依赖于我公司维护的一些自定义可下载库。我正在尝试将这些自定义 dll 添加到构建过程中,以便 nuget 恢复命令能够成功。这些 dll 位于源存储库的“packages”存储库中。如何将这些 dll 添加到构建管道中?任何帮助,将不胜感激!
我目前有一个未在整个应用程序中设置的全局变量。我有两个文件,其中 file2 从 file1 导入。全局在 file1 中初始化。
这是初始化全局变量并稍后在 file1 中使用它的代码。
import time
import asyncio
#Initialize global
CONNECTION_OPEN = False
async def calculate_idle(t):
orig_time = t
global CONNECTION_OPEN
while True:
await asyncio.sleep(5)
print("GLOBAL CONNECTION", CONNECTION_OPEN)
if CONNECTION_OPEN:
print("This value is now true")
else:
print("Value is still false")
Run Code Online (Sandbox Code Playgroud)
这是将全局设置为 true 的 websocket 代码。它位于文件 2 中。
import os
import asyncio
import websockets
import json
import threading
import time
from random import randrange
from enum import Enum
from lights import calculate_idle,CONNECTION_OPEN
async def init_connection(message): …Run Code Online (Sandbox Code Playgroud) typescript ×6
javascript ×4
node.js ×4
jestjs ×3
vue.js ×3
node-fetch ×2
python ×2
python-3.x ×2
vuejs3 ×2
asp.net-core ×1
azure-devops ×1
browser ×1
docker ×1
fluent-ui ×1
openapi ×1
pinia ×1
powershell ×1
reactjs ×1
svg ×1
swagger ×1