require.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. var tap = require('tap');
  3. var spawn = require('child_process').spawn;
  4. var concat = require('concat-stream');
  5. function tape(args) {
  6. var bin = __dirname + '/../bin/tape';
  7. return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname });
  8. }
  9. tap.test('requiring a single module', function (t) {
  10. t.plan(2);
  11. var tc = function (rows) {
  12. t.same(rows.toString('utf8'), [
  13. 'TAP version 13',
  14. '# module-a',
  15. 'ok 1 loaded module a',
  16. '# test-a',
  17. 'ok 2 module-a loaded in same context',
  18. 'ok 3 test ran after module-a was loaded',
  19. '',
  20. '1..3',
  21. '# tests 3',
  22. '# pass 3',
  23. '',
  24. '# ok'
  25. ].join('\n') + '\n\n');
  26. };
  27. var ps = tape('-r ./require/a require/test-a.js');
  28. ps.stdout.pipe(concat(tc));
  29. ps.on('exit', function (code) {
  30. t.equal(code, 0);
  31. });
  32. });
  33. tap.test('requiring multiple modules', function (t) {
  34. t.plan(2);
  35. var tc = function (rows) {
  36. t.same(rows.toString('utf8'), [
  37. 'TAP version 13',
  38. '# module-a',
  39. 'ok 1 loaded module a',
  40. '# module-b',
  41. 'ok 2 loaded module b',
  42. '# test-a',
  43. 'ok 3 module-a loaded in same context',
  44. 'ok 4 test ran after module-a was loaded',
  45. '# test-b',
  46. 'ok 5 module-b loaded in same context',
  47. 'ok 6 test ran after module-b was loaded',
  48. '',
  49. '1..6',
  50. '# tests 6',
  51. '# pass 6',
  52. '',
  53. '# ok'
  54. ].join('\n') + '\n\n');
  55. };
  56. var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js');
  57. ps.stdout.pipe(concat(tc));
  58. ps.on('exit', function (code) {
  59. t.equal(code, 0);
  60. });
  61. });