util.js 802 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { test } from 'ava';
  2. import { removeAsync } from 'fs-extra-promise';
  3. import { mergeOptions, tmpName, tmpFile, tmpDir, compress } from '../dist/lib/util';
  4. test('mergeOptions', async (t) => {
  5. const defaults = {
  6. a: false,
  7. b: 123,
  8. c: '123',
  9. };
  10. const options = mergeOptions(defaults, {
  11. b: undefined,
  12. c: '456',
  13. });
  14. t.deepEqual(options, {
  15. a: false,
  16. b: 123,
  17. c: '456',
  18. });
  19. });
  20. test('compress', async (t) => {
  21. // Don't use `tmpFile`, which keeps the file open and results in exceptions when spawning.
  22. const path = await tmpName();
  23. const code = await compress('./assets/', [ './project/index.html', './project/package.json' ], 'zip', path);
  24. t.is(code, 0);
  25. await removeAsync(path);
  26. });