From 63fc0ac8dd5702ca7f38d41fe0ca2ac21b7fbd55 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 28 Oct 2023 00:26:01 +0200 Subject: Fixed flaky test --- tests/games.spec.js | 22 ++++++++++++---------- tests/root.spec.js | 32 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/tests/games.spec.js b/tests/games.spec.js index 6ff8788..01e692e 100644 --- a/tests/games.spec.js +++ b/tests/games.spec.js @@ -3,23 +3,25 @@ import supertest from 'supertest'; import app from '../main.js'; -describe.concurrent('Games handlers tests', function() { - describe.concurrent('When not logged in', function() { - test('GET /games', async function() { await supertest(app).get('/games').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); - test('GET /games/1', async function() { await supertest(app).get('/games/1').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); - test('GET /games/2', async function() { await supertest(app).get('/games/2').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); +const request = supertest(app); + +describe('Games handlers tests', function() { + describe('When not logged in', function() { + test('GET /games', async function() { await request.get('/games').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); + test('GET /games/1', async function() { await request.get('/games/1').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); + test('GET /games/2', async function() { await request.get('/games/2').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); }); - describe.concurrent('With valid credentials', function() { + describe('With valid credentials', function() { beforeEach(async function(ctx) { - const authResponse = await supertest(app).post('/login') + const authResponse = await request.post('/login') .send('username=Alice&password=Alice42!') .expect('Content-Type', /text\/plain/) .expect('set-cookie', /JDMSessionId=/) .expect(302, /Redirecting to \/games$/); ctx.cookie = authResponse.get('Set-Cookie'); }); - test('GET /games', async function(ctx) { await supertest(app).get('/games').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, /Alice vs Bob<\/a><\/td>/); }); - test('GET /games/1', async function(ctx) { await supertest(app).get('/games/1').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, /

Alice vs Bob<\/h2>/); }); - test('GET /games/2', async function(ctx) { await supertest(app).get('/games/2').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games/); }); + test('GET /games', async function(ctx) { await request.get('/games').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, /Alice vs Bob<\/a><\/td>/); }); + test('GET /games/1', async function(ctx) { await request.get('/games/1').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, /

Alice vs Bob<\/h2>/); }); + test('GET /games/2', async function(ctx) { await request.get('/games/2').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games/); }); }); }); diff --git a/tests/root.spec.js b/tests/root.spec.js index e422575..968ea5d 100644 --- a/tests/root.spec.js +++ b/tests/root.spec.js @@ -1,18 +1,18 @@ -import { beforeEach, describe, it } from 'vitest'; +import { beforeEach, describe, test } from 'vitest'; import supertest from 'supertest'; import app from '../main.js'; const request = supertest(app); -describe.concurrent('Root handlers tests', function() { - describe.concurrent('When not logged in', function() { - it('GET /', async function() { await request.get('/').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); - it('GET /login', async function() { await request.get('/login').expect('Content-Type', /text\/html/).expect(200, /
/); }); - it('GET /logout', async function() { await request.get('/logout').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/$/); }); +describe('Root handlers tests', function() { + describe('When not logged in', function() { + test('GET /', async function() { await request.get('/').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); + test('GET /login', async function() { await request.get('/login').expect('Content-Type', /text\/html/).expect(200, //); }); + test('GET /logout', async function() { await request.get('/logout').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/$/); }); }); - describe.concurrent('With valid credentials', function() { + describe('With valid credentials', function() { beforeEach(async function(ctx) { const authResponse = await request.post('/login') .send('username=Alice&password=Alice42!') @@ -21,27 +21,27 @@ describe.concurrent('Root handlers tests', function() { .expect(302, /Redirecting to \/games$/); ctx.cookie = authResponse.get('Set-Cookie'); }); - it('GET /', async function(ctx) { await request.get('/').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games$/); }); - it('GET /login', async function(ctx) { await request.get('/login').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games$/); }); + test('GET /', async function(ctx) { await request.get('/').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games$/); }); + test('GET /login', async function(ctx) { await request.get('/login').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games$/); }); describe('logout', function() { beforeEach(async function(ctx) { await request.get('/logout').set('cookie', ctx.cookie).expect('content-type', /text\/plain/).expect('set-cookie', /JDMSessionId=;/).expect(302, /Redirecting to \/$/); }); - describe.concurrent('all handlers with the now invalid cookie', async function() { - it('GET /', async function(ctx) { await request.get('/').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); - it('GET /login', async function(ctx) { await request.get('/login').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, //); }); - it('GET /logout', async function(ctx) { await request.get('/logout').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/$/); }); + describe('all handlers with the now invalid cookie', function() { + test('GET /', async function(ctx) { await request.get('/').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); }); + test('GET /login', async function(ctx) { await request.get('/login').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, //); }); + test('GET /logout', async function(ctx) { await request.get('/logout').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/$/); }); }); }); }); - describe.concurrent('With invalid credentials', function() { - it('POST /login', async function() { + describe('With invalid credentials', function() { + test('POST /login', async function() { await request.post('/login').send('username=NonExistant&password=Alice42!') .expect('Content-Type', /text\/html/) .expect(403, /erreur de connexion/); }); - it('POST /login', async function() { + test('POST /login', async function() { await request.post('/login').send('username=Alice&password=Invalid') .expect('Content-Type', /text\/html/) .expect(403, /erreur de connexion/); -- cgit v1.2.3