node.js - 如何使用 Jenkinsfile 执行 Node.JS API 测试用例

标签 node.js git api jenkins continuous-integration

我是 Jenkins 的新手。我有一个小型 Node .JS 服务器,测试用例是使用 Mocha 编写的(集成测试用例,而不是单元测试用例)。我正在尝试使用 Jenkins 为此创建一个 CI 管道。我的 Jenkinsfile 如下所示:

 #!/usr/bin/env groovy

pipeline {

    agent {
        docker {
            image 'node'
            args '-u root'
        }
    }

    stages {
        stage('Build') {
            steps {
                echo 'Installing Dependencies...'
                sh 'npm install'
            }
        }
        stage('Run') {
            steps {
                echo 'Starting application...'
                sh 'npm start'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...'
                sh 'npm test'
            }
        }
    }
 }

在运行阶段,使用命令node server.js启动服务器,一旦服务器启动,我希望针对该服务器执行测试用例。但我注意到, Jenkins 从不执行测试阶段,因为服务器保持启动状态(这就是我想要的),并且不会从中退出。 如何启动服务器并针对该服务器运行测试阶段?

最佳答案

您应该在运行服务器之前运行测试。测试不应依赖于正在运行的服务器。测试应该需要任何所需的内容并进行测试,然后您应该运行服务器。

https://github.com/jenkinsci/pipeline-examples/tree/master/jenkinsfile-examples/nodejs-build-test-deploy-docker-notify

关于node.js - 如何使用 Jenkinsfile 执行 Node.JS API 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48222100/

相关文章:

git - Gstatus 改变了 vim-fugitive 中的行为

delphi - 如何使用 SQL 以编程方式访问 Windows Live 照片库中的面部识别缓存?

git shallow clone - 我如何删除 "grafted tag"它是什么?

node.js - 新的连接导致当前连接停止工作

javascript - 你可以存储对 mongo 集合的引用吗?

node.js - 为什么 Travis CI 报告构建成功,即使 npm 发布失败?

git - 无法连接到 github.com 端口 443 : Connection refused, 引导失败,Discourse Docker

javascript - Windows Live API 连接问题

perl - 有没有人能够让 Confluence.pm 添加附件?

javascript - 如何在node.js中获取window.location.hash中的变量