Chai Tests Crash Sudoku Solver

Hello Friends,

I have been writing the functional tests for the Sudoku Solver and all of my tests pass but upon completion they immediately cause my app to crash, does anyone have any tips on how exactly to troubleshoot this issue?

Sometimes the app will refresh itself after a bit will be okay until the tests try to run again. I do not appear to have any issues with my unit tests. I have tried commenting out certain parts of the code for troubleshooting but unless I remove all of the functional tests the app will crash. My app is running on repl.it if that is relevant at all.

The functional test code is below and the link to all of my code is here

Thank you for your help.

const chai = require("chai");
const chaiHttp = require('chai-http');
const assert = chai.assert;
const server = require('../server');

chai.use(chaiHttp);

suite('Functional Tests', () => {
  
  suite('POST requests to /api/solve', () => {

    test('Solve puzzle with valid string /api/solve', function(done) {
      chai.request(server)
      .post('/api/solve')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.'})
      .end(function(err, res) {
        assert.equal(res.status, 200);
        assert.equal(res.body.solution, '135762984946381257728459613694517832812936745357824196473298561581673429269145378');
        done();
      })
    });

    test('Solve puzzle with missing puzzle string /api/solve', function(done) {
      chai.request(server)
      .post('/api/solve')
      .send({})
      .end(function(err, res) {
        assert.equal(res.body.error, 'Required field missing');
        done();
      })
    });

    test('Solve puzzle with invalid characters in puzzle string /api/solve', function(done) {
      chai.request(server)
      .post('/api/solve')
      .send({puzzle: '1.5..2.84..P3.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.'})
      .end(function(err, res) {
        assert.equal(res.body.error, 'Invalid characters in puzzle');
        done();
      })
    });


    test('Solve puzzle with incorrect length /api/solve', function(done) {
      chai.request(server)
      .post('/api/solve')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16..'})
      .end(function(err, res) {
        assert.equal(res.body.error, 'Expected puzzle to be 81 characters long');
        done();
      })
    });    

    test('Solve puzzle that cannot be solved /api/solve', function(done) {
      chai.request(server)
      .post('/api/solve')
      .send({puzzle: '1.5..2.44..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.'})
      .end(function(err, res) {
        assert.equal(res.body.error, 'Puzzle cannot be solved');
        done();
      })
    });

  })


  suite('POST Requests to /api/check', () => {

    test('Check a puzzle placement with all fields /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'A2', value: '3'})
      .end(function(err, res) {
        assert.equal(res.status, 200);
        assert.equal(res.body.valid, true);
        done();
      })
    }); 

    test('Check a puzzle with single placement conflict /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'A2', value: '4'})
      .end(function(err, res) {
        assert.equal(res.body.valid, false);
        assert.equal(res.body.conflict[0], 'row');
        done();
      })
    });

    test('Check a puzzle with multiple placement conflicts /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'F7', value: '2'})
      .end(function(err, res) {
        assert.equal(res.body.valid, false);
        assert.equal(res.body.conflict[0], 'row');
        assert.equal(res.body.conflict[1], 'column');
        done();
      })
    }); 

    test('Check a puzzle with all placement conflicts /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'C1', value: '2'})
      .end(function(err, res) {
        assert.equal(res.body.valid, false);
        assert.equal(res.body.conflict[0], 'row');
        assert.equal(res.body.conflict[1], 'column');
        assert.equal(res.body.conflict[2], 'region');
        done();
      })
    });

    test('Check a puzzle placement with missing required fields /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'A2'})
      .end(function(err, res) {
        assert.equal(res.body.error, "Required field(s) missing");
        done();
      })
    });

    test('Check a puzzle placement with invalid characters /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5+....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'A2', value: '3'})
      .end(function(err, res) {
        assert.equal(res.body.error, "Invalid characters in puzzle");
        done();
      })
    });

    test('Check a puzzle placement with incorrect length /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.3', coordinate: 'A2', value: '3'})
      .end(function(err, res) {
        assert.equal(res.body.error, "Expected puzzle to be 81 characters long");
        done();
      })
    });


    test('Check a puzzle placement with invalid placement coordinate /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'J2', value: '3'})
      .end(function(err, res) {
        assert.equal(res.body.error, "Invalid coordinate");
        done();
      })
    });

    test('Check a puzzle placement with invalid placement value /api/check', function(done) {
      chai.request(server)
      .post('/api/check')
      .send({puzzle: '1.5..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.', coordinate: 'A2', value: '3P'})
      .end(function(err, res) {
        assert.equal(res.body.error, 'Invalid value');
        done();
      })
    });


  }) 

});

I’m not sure if this is because of testing. Sometimes everything is still working after tests finish, without the “refresh”, sometimes it appears to be hanging.

I am sorry I never replied, I forgot to come back to this topic :sweat_smile:

I think you probably correct. After searching & reading posts from others, I suspect it could be a bandwidth issue with repl.it as I only have a free account :woman_shrugging:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.