小编Skh*_*haz的帖子

考虑使用“jsdom”测试环境

我有这个简单的测试:

import React from 'react'
import { render } from '@testing-library/react'

import Button from '.'

describe('Button', () => {
  it('renders button without crashing', () => {
    const label = 'test'

    render(<Button label={label} />)
  })
})

Run Code Online (Sandbox Code Playgroud)

我有一个jest.config.json包含此内容的

{
  "setupFilesAfterEnv": [
    "<rootDir>/lib/settings/setupTests.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我的setupTests.ts我有

import '@testing-library/jest-dom'
Run Code Online (Sandbox Code Playgroud)

当我运行npm run test(刚刚运行jest)时,出现以下错误:

下面的错误可能是由于使用了错误的测试环境导致的,参见 https://jestjs.io/docs/configuration#testenvironment-string

考虑使用“jsdom”测试环境。

我做错了什么?这在升级之前曾经有效。

javascript typescript reactjs react-testing-library

84
推荐指数
2
解决办法
9万
查看次数

在平面布局中发现多个顶级包

我正在尝试从使用 Poetry 的源代码安装一个库,但出现此错误

error: Multiple top-level packages discovered in a flat-layout: ['tulips', 'fixtures'].
        
To avoid accidental inclusion of unwanted files or directories,
setuptools will not proceed with this build.
        
If you are trying to create a single distribution with multiple packages
on purpose, you should not rely on automatic discovery.
Instead, consider the following options:
        
1. set up custom discovery (`find` directive with `include` or `exclude`)
2. use a `src-layout`
3. explicitly set `py_modules` or `packages` with a list of …
Run Code Online (Sandbox Code Playgroud)

python python-poetry

64
推荐指数
2
解决办法
4万
查看次数

无法从 watchpack-chokidar2:fsevents 访问 NPM CI 错误绑定

当我npm ci在 Github Actions 上运行时,出现错误:

Run npm ci
npm ERR! bindings not accessible from watchpack-chokidar2:fsevents

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-09-17T15_18_42_465Z-debug.log
Error: Process completed with exit code 1.
Run Code Online (Sandbox Code Playgroud)

可以是什么?

我的.github/workflows/eslint.yaml

name: ESLint

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '14.x'
      - run: npm ci
      - run: npm run lint
Run Code Online (Sandbox Code Playgroud)

我的package.json

Run npm ci
npm ERR! …
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm package.json github-actions

11
推荐指数
1
解决办法
2万
查看次数

TypeScript 字体导入,链接标签属性 crossorigin 出错

导入自定义字体(例如谷歌字体)时如何解决此打字稿错误。

<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
Run Code Online (Sandbox Code Playgroud)

这里是错误的详细信息:

Type 'boolean' is not assignable to type 'string'.ts(2322)
index.d.ts(2279, 9): The expected type comes from property 'crossOrigin' which is declared here on type 'DetailedHTMLProps<LinkHTMLAttributes<HTMLLinkElement>, HTMLLinkElement>'
Run Code Online (Sandbox Code Playgroud)

使固定:

  • 属性是:crossOrigin,而不是crossorigin(O是大写的)
  • crossOrigin 接受一个字符串。如果您在链接标记中添加 crossOrigin,则<link ... crossOrigin />您正在编写的这是一个布尔值(期望 true 或 false),而它需要一个字符串。这就是为什么将其设置为 crossOrigin="anonymous" 会起作用的原因
  • 从 v10.2 开始,Next.js 具有内置的 Web 字体优化功能,这意味着您可以将其删除并且它会起作用

fonts typescript next.js

11
推荐指数
1
解决办法
1万
查看次数

“node_modules/minimatch/dist/cjs/index””没有导出成员“IOptions”

我有一个要在 Firebase 函数上运行的 TypeScript 项目。

这是我的tsconfig.json

{
  "compilerOptions": {
    "lib": ["es2017"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "dist",
    "sourceMap": true,
    "target": "es2017",
    "esModuleInterop": true,
    "strict": true
  },
  "include": ["src"],
  "exclude": ["dist", "node_modules"]
}
Run Code Online (Sandbox Code Playgroud)

当我构建时(npm run build,运行 tsc)

我收到错误

node_modules/@types/glob/index.d.ts:29:42 - 错误 TS2694:命名空间 '"/opt/workspace/personal/kioskify-backend/functions/node_modules/minimatch/dist/cjs/index"' 没有导出成员“IOptions”。

29 接口 IOptions 扩展 minimatch.IOptions {

编辑:错误发生在其他模块中。完整输出:

npm run build

> build
> npm run lint && tsc


> lint
> eslint --fix .

node_modules/@types/glob/index.d.ts:29:42 - error TS2694: Namespace '"/opt/workspace/personal/kioskify-backend/functions/node_modules/minimatch/dist/cjs/index"' has no exported member 'IOptions'.

29 …
Run Code Online (Sandbox Code Playgroud)

node.js typescript

9
推荐指数
2
解决办法
4969
查看次数

模拟访问公共 GCS 存储桶的结果

我有以下代码:

bucket = get_bucket('bucket-name')
blob = bucket.blob(os.path.join(*pieces))
blob.upload_from_string('test')
blob.make_public()
result = blob.public_url
# result is `<Mock name='mock().get_bucket().blob().public_url`
Run Code Online (Sandbox Code Playgroud)

我想模拟public_url的结果,我的单元测试代码是这样的

with ExitStack() as st:
    from google.cloud import storage
    blob_mock = mock.Mock(spec=storage.Blob)
    blob_mock.public_url.return_value = 'http://'

    bucket_mock = mock.Mock(spec=storage.Bucket)
    bucket_mock.blob.return_value = blob_mock

    storage_client_mock = mock.Mock(spec=storage.Client)
    storage_client_mock.get_bucket.return_value = bucket_mock

    st.enter_context(
        mock.patch('google.cloud.storage.Client', storage_client_mock))
    my_function()
Run Code Online (Sandbox Code Playgroud)

谷歌存储有没有像FakeRedismoto这样的东西,所以我可以模拟google.cloud.storage.Blob.public_url

mocking google-api google-cloud-storage python-unittest google-cloud-python

8
推荐指数
1
解决办法
1584
查看次数

如何使用 GitHub Actions 缓存 firebase/emulators 目录

我正在使用 firebase 模拟器来运行测试,并且收到了有关使用缓存系统进行优化的警告。

我怎样才能做到这一点?

看起来您正在 CI 环境中运行。您可以通过缓存 /home/runner/.cache/firebase/emulators 目录来避免重复下载 Firestore 模拟器。

firebase-tools github-actions

8
推荐指数
2
解决办法
2011
查看次数

Sentry:在使用 React 时启用可读的堆栈跟踪

我正在使用 Sentry 通过 Netlify 的插件捕获生产中的任何错误以上传source maps.

我收到消息:

在此处输入图片说明

匹配您的配置时出错。请配置堆栈跟踪链接以解决此问题。

我应该在“堆栈跟踪根”和“源代码根”中填写什么?

在此处输入图片说明

sentry reactjs netlify

8
推荐指数
0
解决办法
177
查看次数

Firestore 吓坏了

我刚刚在另一个域(生产 url)下打开了我的项目,当我打开网络请求时,我看到了这个:

https://i.imgur.com/NxgTmIf.mp4

这花了很长时间(8 分钟或更长时间),我的 CPU 热得要命,我做错了什么?

我的应用程序很简单,我怀疑它的根源是这段代码:

  const [items, setItems] = useState([]);

  const publish = async () => {
    const batch = firestore.batch();

    items.forEach(({ id }, index) => {
      batch.update(firestore.collection('v1').doc(id), { '#': index });
    });

    await batch.commit();
  };

  const onCompletion = querySnapshot => {
    const arr = [];

    querySnapshot.forEach(document => {
      const { vid: { id: vid }, '#': index } = document.data();

      const { id } = document;

      arr.push({ id, vid, index });
    });

    setItems(arr);
  };

  useEffect(() => …
Run Code Online (Sandbox Code Playgroud)

javascript firebase reactjs google-cloud-firestore

7
推荐指数
1
解决办法
192
查看次数

php8.1-bcmath :取决于: php8.1-common (= 8.1.2-1ubuntu2) 但要安装 8.1.2-1ubuntu4

我正在升级使用 PHP 7.4 的映像,现在计划使用 PHP 8.1。

但是,我收到错误

php8.1-bcmath :取决于:php8.1-common (= 8.1.2-1ubuntu2),但要安装 8.1.2-1ubuntu4 php8.1-fpm :取决于:php8.1-common (= 8.1.2- 1ubuntu2) 但要安装 8.1.2-1ubuntu4

在这条线上

apt install php8.1-bcmath php8.1-fpm php8.1-common
Run Code Online (Sandbox Code Playgroud)

我应该做什么来安装这些依赖项?

php ubuntu

7
推荐指数
2
解决办法
1万
查看次数