I'm trying to run tests with mocha and supertest on an express nodejs app and the issue is that the GitLab runner on which the tests are executed automatically passes them even when they are wrong and should raise an error.
I have the correct outputs when I run them locally.
I'm new to these frameworks / technologies.
My tests:
var supertest = require("supertest");
var should = require("should");
var server = supertest.agent("http://localhost:8080");
// UNIT test begin
describe("SAMPLE unit test",function(){
// #1 should return home page
server.get('/', function(req, res) {
tst = res.status(200).json({ "message": "hello world" });
console.log(tst);
});
it("should return home page",function(done){
// calling home page api
server
.get("/")
.expect("Content-type",/json/)
.expect(200) // THis is HTTP response
.end(function(err,res){
// HTTP status should be 200
//res.status.should.equal(200);
// Error key should be false.
//res.body.error.should.equal(false);
console.log(res);
done();
});
});
it("should login",function(done){
// calling home page api
server
.post("/api/auth/signin")
.send({"email":"emile.dadou@epsi.fr","password":"preudhomme"})
.expect("Content-type",/json/)
.expect(200) // THis is HTTP response
.end(function(err,res){
// HTTP status should be 200
//res.status.should.equal(200);
// Error key should be false.
//res.body.error.should.equal(false);
console.log(res);
done();
});
});
it("should raise an error",function(done){
// calling home page api
server
.get("/gné") // this route doesn't exist
.expect("Content-type",/json/)
.expect(200) // THis is HTTP response
.end(function(err,res){
// HTTP status should be 200
res.status.should.equal(200);
// Error key should be false.
res.body.error.should.equal(false);
console.log(res);
done();
});
});
});
And here is my.gitlab-ci.yml file:
image: node:latest
stages:
- build
- tests
build:
type: build
stage: build
script:
- ls -l
- npm i
- npm run build --if-present
- npm start server.js
- npm test
tests:
type: test
stage: tests
script:
- npm i
- npm test
So after a push the pipeline starts and after I have these outputs:
on the other when I execute the tests locally I have the right outputs (2 pass and 1 failing) like this:
Is there something that I'm missing or done wrong? How can I have the same outputs in GitLab?
After trying different configurations i found out that the issue came from the server that i was talking to wasn't running
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.