tasks.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global describe, it, beforeEach, afterEach */
  6. 'use strict';
  7. const mockery = require( 'mockery' );
  8. const sinon = require( 'sinon' );
  9. describe( 'build-tasks', () => {
  10. let sandbox, tasks, rollupBundleMock, rollupBundleWriteMock;
  11. const config = {
  12. ROOT_DIR: '.',
  13. BUILD_DIR: 'build',
  14. BUNDLE_DIR: 'bundle',
  15. MAIN_FILE: 'ckeditor.js'
  16. };
  17. beforeEach( () => {
  18. mockery.enable( {
  19. warnOnReplace: false,
  20. warnOnUnregistered: false
  21. } );
  22. sandbox = sinon.sandbox.create();
  23. rollupBundleWriteMock = sandbox.spy();
  24. rollupBundleMock = {
  25. write: rollupBundleWriteMock
  26. };
  27. mockery.registerMock( 'rollup', {
  28. rollup: () => {
  29. return {
  30. then: ( resolve ) => {
  31. resolve( rollupBundleMock );
  32. }
  33. };
  34. }
  35. } );
  36. tasks = require( '../../tasks/bundle/tasks' )( config );
  37. } );
  38. afterEach( () => {
  39. mockery.disable();
  40. sandbox.restore();
  41. } );
  42. describe( 'generate', () => {
  43. it( 'should use rollup to generate js bundle and save bundled file', () => {
  44. tasks.generate();
  45. sinon.assert.calledWithExactly( rollupBundleWriteMock, {
  46. dest: 'bundle/ckeditor.js',
  47. format: 'iife',
  48. moduleName: 'createEditor'
  49. } );
  50. } );
  51. } );
  52. } );