小编ken*_*des的帖子

如何gitignore快照文件夹?

我开始学习有关Jest和测试(例如快照测试)的更多信息。我在React中配置组件的方式是...

- src
  - components
    - Component1
      - index.js
      - __tests__
        - Component1.test.js
        - __snapshots__
  - Component2
      - index.js
      - __tests__
        - Component2.test.js
        - __snapshots__
Run Code Online (Sandbox Code Playgroud)

等等。

我想知道要写什么.gitignore来忽略__snapshots__此结构的文件夹。

目前我有这个(错了)

/src/components/*/__snapshots__/

另外,最好是将它们保留在版本控制中还是忽略它们?我仍然想知道我需要放入什么gitignore,但也想听听对此的想法!

谢谢!

javascript git testing reactjs jestjs

10
推荐指数
2
解决办法
1895
查看次数

componentDidMount 多次获取调用最佳实践?

我有很多彼此独立的 api,需要在呈现之前存储在 React 状态中。我有fetch电话,componentDidMount但我不确定解决这个问题的最佳方法是什么。我应该... 1. 嵌套 fetch 调用

例子:

componentDidMount() {
    fetch('url')
    .then((res) => res.json())
    .then((data) => {
        // call another fetch in here
    })

}
Run Code Online (Sandbox Code Playgroud)

或 2. 有单独的 fetch 调用

例子:

componentDidMount() {
    fetch('url')
    .then((res) => res.json())
    .then((data) => {
        // set state in here
    })

    // call another fetch for the other url endpoint
    fetch('url2')
    .then((res) => res.json())
    .then((data) => {
        // set state in here
    })
}
Run Code Online (Sandbox Code Playgroud)

我不确定一种方式是否被认为比另一种更好,但我很想知道你们的想法以及一些优点/缺点是什么。

更新:我现在正在使用 Promise.all(),但我返回的是 Promise 而不是实际值。这是我的代码:

Promise.all([ …
Run Code Online (Sandbox Code Playgroud)

javascript api fetch reactjs

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

AttributeError:'decimal.Decimal'对象没有属性'decode'

我很难弄清楚为什么会收到此错误。我有一个称为Driver的模型,这是代码:

class Driver(models.Model):
userId = models.IntegerField(unique=True)
status = models.IntegerField(default=-1)
currentLatitude = models.DecimalField(max_digits=11, decimal_places=8, default=0)
currentLongitude = models.DecimalField(max_digits=11, decimal_places=8, default=0)
Run Code Online (Sandbox Code Playgroud)

我正在尝试在tests.py文件中测试该模型,并且在我的setUpTestData(cls)方法中创建了一个像这样的Driver实例。

Driver.objects.create(userId=3, status=0, currentLatitude=37.717, currentLongitude=100)

我只是为经度/纬度放置了伪虚拟值,我想测试此实例的currentLatitude是否实际为37.717,currentLongitude是否为100。

这是我的测试之一:

    def testDriverLatitude(self):
        driver = Driver.objects.get(id=3)
        expected_latitude = driver.currentLatitude
        self.assertEquals(expected_latitude, 37.717)
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,出现错误 driver = Driver.objects.get(id=1)

这是我得到的错误 AttributeError: 'decimal.Decimal' object has no attribute 'decode'

这是完整的跟踪堆栈

Traceback (most recent call last):
File "\server\backend\tests.py", line 51, in 
testDriverLatitude
driver = Driver.objects.get(id=3)
File "C:\Users\Andy\.virtualenvs\CS160-wrkGRq_z\lib\site- 
packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Andy\.virtualenvs\CS160-wrkGRq_z\lib\site- …
Run Code Online (Sandbox Code Playgroud)

python django django-models django-testing

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

将数字插入随机数组

我需要一些帮助将数字8插入到一个给我随机值的数组中.数组必须按顺序排列.例如,如果我有一个(1,5,10,15)的数组,我必须在5和10之间插入数字8.我有一个问题,我怎么能找到一个方法来找到8将放置因为数组是随机的,它可以是任何东西.到目前为止,这是我的代码:

public class TrickyInsert {

public static void main(String[] args) {

    int[] mysteryArr = generateRandArr();

    //print out starting state of mysteryArr:
    System.out.print("start:\t");
    for ( int a : mysteryArr ) {
        System.out.print( a + ", ");
    }
    System.out.println();


    //code starts below

    // insert value '8' in the appropriate place in mysteryArr[]
    int[] tmp = new int[mysteryArr.length + 1];
    int b = mysteryArr.length;
    for(int i = 0; i < mysteryArr.length; i++) {
        tmp[i] = mysteryArr[i];

    }
    tmp[b] = 8;
    for(int i =b …
Run Code Online (Sandbox Code Playgroud)

java arrays

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

后端和前端位于同一个 kubernetes yaml 文件中?

当我尝试通过 Google Kubernetes Engine (GKE) 将我的 Web 应用程序部署到 Kubernetes 上时,我正在深入研究 nginx、Kubernetes 和 SSL。

关于我的项目的一些信息:

  • 我的前端是一个 React Web 应用程序
  • 我的后端是 Node Express API 服务

它们位于不同的存储库中(例如:前端存储库和后端存储库)

我计划使用 nginx 来服务我的前端和代理请求到我的后端。

我的问题是...

是否可以将我的后端和前端放在同一个 Kubernetes 配置 yaml 文件中?如果可能,这是这样做的最佳实践吗?

我怎么看是...

在我的nginx.conf文件中,我将有一个服务器部分,其中有一个proxy_pass类似于 的内容localhost:8000,这是后端的端口。我认为如果两者都在同一个容器和本地网络中,这会起作用。

然后我可能会有一个指向 nginx 的负载均衡器。

任何帮助或建议表示赞赏!我希望这是有道理的(对此仍然很新)!

deployment proxy nginx kubernetes google-kubernetes-engine

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