open-report.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import test from 'ava';
  2. import path from 'path';
  3. import proxyquire from 'proxyquire';
  4. import fn from '..';
  5. process.chdir(__dirname);
  6. test('opens nothing when there are no errors nor warnings', async t => {
  7. const glob = path.join(__dirname, 'fixtures/open-report/successes/*');
  8. const results = await fn.lintFiles(glob);
  9. const openReport = proxyquire('../lib/open-report', {
  10. 'open-editor': () => t.fail()
  11. });
  12. openReport(results);
  13. t.pass();
  14. });
  15. test('only opens errors if there are errors and warnings', async t => {
  16. const glob = path.join(__dirname, 'fixtures/open-report/**');
  17. const results = await fn.lintFiles(glob);
  18. const expected = [
  19. {
  20. file: path.join(__dirname, 'fixtures/open-report/errors/one.js'),
  21. line: 1,
  22. column: 7
  23. },
  24. {
  25. file: path.join(__dirname, 'fixtures/open-report/errors/two-with-warnings.js'),
  26. line: 1,
  27. column: 1
  28. },
  29. {
  30. file: path.join(__dirname, 'fixtures/open-report/errors/three.js'),
  31. line: 1,
  32. column: 7
  33. }
  34. ];
  35. const openReport = proxyquire('../lib/open-report', {
  36. 'open-editor': files => t.deepEqual(files, expected)
  37. });
  38. openReport(results);
  39. });
  40. test('if a file has errors and warnings, it opens the first error', async t => {
  41. const glob = path.join(__dirname, 'fixtures/open-report/errors/two-with-warnings.js');
  42. const results = await fn.lintFiles(glob);
  43. const expected = [
  44. {
  45. file: path.join(__dirname, 'fixtures/open-report/errors/two-with-warnings.js'),
  46. line: 1,
  47. column: 1
  48. }
  49. ];
  50. const openReport = proxyquire('../lib/open-report', {
  51. 'open-editor': files => t.deepEqual(files, expected)
  52. });
  53. openReport(results);
  54. });
  55. test('only opens warnings if there are no errors', async t => {
  56. const glob = path.join(__dirname, 'fixtures/open-report/warnings/*');
  57. const results = await fn.lintFiles(glob);
  58. const expected = [
  59. {
  60. file: path.join(__dirname, 'fixtures/open-report/warnings/one.js'),
  61. line: 1,
  62. column: 1
  63. },
  64. {
  65. file: path.join(__dirname, 'fixtures/open-report/warnings/three.js'),
  66. line: 1,
  67. column: 1
  68. }
  69. ];
  70. const openReport = proxyquire('../lib/open-report', {
  71. 'open-editor': files => t.deepEqual(files, expected)
  72. });
  73. openReport(results);
  74. });