контрольный пример мокко чай не завершается автоматически - PullRequest
0 голосов
/ 20 декабря 2018

Я написал следующие тестовые примеры на mocha-chai, и он отлично работает и показывает все успешно пройденные результаты.Но это не прекращает выполнение после успешного прохождения всех 6 тестовых случаев.Я не знаю, по какой причине мой тестовый случай не завершается автоматически, мне нужно нажать CTRL + C, чтобы завершить тестовый случай.

Я не знаю, по какой причине тест былуспешно пройден, но не завершается.Я также написал done () в конце теста, но все равно он не работает

Я использовал PostgreSQL в качестве базы данных и NodeJS в качестве внутреннего сервера.

test.js

const { colors } = require('mocha/lib/reporters/base');

colors.pass = 32;
const { describe, it } = require('mocha');
const { expect } = require('chai');
const request = require('superagent');
const should = require('should');
const fs = require('fs');
const path = require('path');
const moment = require('moment-timezone');

const envPath = path.join(__dirname, '.env');
require('dotenv').config({ path: envPath });

const Sequelize = require('sequelize');
const db = require('../db/models');

// Test that server is running or not
describe('Unit tests for add user', () => {
    // Gateway api test case and it's works fine
});

// Read the test cases stored from database and stored in an array
describe('Test Cases', () => {
    // Read the test cases from database
});

// Test case to write test data in csv and upload the csv and insert user information in csv

describe('Process data user csv', () => {    

    it('create user csv to write data in csv', done => {
        // Create user csv from test data and it's passed and successfully completed it
    });

    it('Upload user csv and insert the user in the database with accurate data', done => {
        // Upload user csv and insert user information from csv and it's passed and successfully completed it
    });

    it('verify user information from user table', done => {
        // This method verifies the user data stored user table, which has inserted in test case.
        // Sequlieze query which fetch the user information 

        TestService.executeQuery(
            dbQuery.qGetUserDetails,
            {
            email: arrTestCases[0].expected_result.email,
            },
            'select'
        )
        .then(data => {
            should(data[0].email).equal(arrTestCases[0].expected_result.email);
            done();
        });        
    });
  });
});

app.query.js

/**
 * @description default queries
 */
module.exports = {
  qGetUserDetails: `select * from "Users" where email = :email and is_active = true and is_deleted = false`,
};

Test.service.js

/**
 * @class TestService
 */
const Sequelize = require('sequelize');
const db = require('../db/models');

module.exports = class TestService {

  /**
   * @static execute query
   * @param {*} query
   * @param {*} replacements
   * @param {*} operation
   * @memberof TestService
   */
  static executeQuery(query, replacements, operation) {
    return new Promise((resolve, reject) => {
      let queryType;
      if (operation === 'insert') {
        queryType = Sequelize.QueryTypes.INSERT;
      } else if (operation === 'update') {
        queryType = Sequelize.QueryTypes.UPDATE;
      } else if (operation === 'select') {
        queryType = Sequelize.QueryTypes.SELECT;
      } else if (operation === 'delete') {
        queryType = Sequelize.QueryTypes.DELETE;
      } else {
        queryType = Sequelize.QueryTypes.SELECT;
      }
      return db.sequelize
        .query(query, { replacements, type: queryType, raw: true })
        .then(data => resolve(data))
        .catch(err => reject(err));
    });
  }
};

1 Ответ

0 голосов
/ 21 декабря 2018

Я не знаю, по какой причине тест был успешно пройден, но не завершается.

Вы не закрываете дескриптор базы данных, когда все тесты были выполнены, чтоозначает, что Node.js не знает, что вы сделали.

Вы можете добавить хук корневого уровня after, чтобы закрыть его:

after(() => {
  sequelize.close();
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...