bootstrap.js 777 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const assert = require('power-assert');
  3. const path = require('path');
  4. const mock = require('./index').default;
  5. const options = {};
  6. if (process.env.EGG_BASE_DIR) options.baseDir = process.env.EGG_BASE_DIR;
  7. // throw error when an egg plugin test is using bootstrap
  8. const pkgInfo = require(path.join(options.baseDir || process.cwd(), 'package.json'));
  9. if (pkgInfo.eggPlugin) throw new Error('DO NOT USE bootstrap to test plugin');
  10. const app = mock.app(options);
  11. if (typeof beforeAll === 'function') {
  12. // jest
  13. beforeAll(() => app.ready());
  14. } else {
  15. // mocha
  16. before(() => app.ready());
  17. }
  18. afterEach(() => app.backgroundTasksFinished());
  19. // restore should be the last one
  20. afterEach(mock.restore);
  21. module.exports = {
  22. assert,
  23. app,
  24. mock,
  25. mm: mock,
  26. };