You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.6 KiB

10 months ago
  1. 'use strict';
  2. /*jshint asi: true, browser: true */
  3. var test = require('tape');
  4. +function setup() {
  5. function createEditorElem(lang) {
  6. var elem = document.createElement('div')
  7. elem.setAttribute('id', lang + '-editor')
  8. elem.setAttribute('class', 'editor')
  9. document.body.appendChild(elem)
  10. }
  11. function loadStyle() {
  12. var css = require('./stringified/style');
  13. var head = document.getElementsByTagName('head')[0];
  14. var style = document.createElement('style');
  15. style.type = 'text/css';
  16. if (style.styleSheet){
  17. style.styleSheet.cssText = css;
  18. } else {
  19. style.appendChild(document.createTextNode(css));
  20. }
  21. head.appendChild(style);
  22. }
  23. ['javascript', 'coffee', 'json', 'lua', 'xml'].forEach(createEditorElem);
  24. loadStyle();
  25. require('./fixtures/javascript-editor');
  26. require('./fixtures/coffee-editor');
  27. require('./fixtures/json-editor');
  28. require('./fixtures/lua-editor');
  29. require('./fixtures/xml-editor');
  30. }()
  31. test('error annotations provided by inlined worker', function (t) {
  32. function getError(lang) {
  33. var editor = document.getElementById(lang + '-editor');
  34. var errors = editor.getElementsByClassName('ace_error')
  35. return { length: errors.length, line: errors[0] && errors[0].textContent }
  36. }
  37. // give editors time to initialize and workers to do the annotations
  38. var jsCount = 0
  39. , coffeeCount = 0
  40. , jsonCount = 0
  41. , luaCount = 0
  42. , xmlCount = 0;
  43. var max = 10; // give it a max of 10 seconds
  44. +function javascript() {
  45. var err = getError('javascript')
  46. if (!err.length && ++jsCount < max) return setTimeout(javascript, 1000)
  47. t.equal(err.length, 1, 'javascript editor shows one error')
  48. t.equal(err.line, '5', 'on line 5')
  49. }()
  50. +function coffee() {
  51. var err = getError('coffee')
  52. if (!err.length && ++coffeeCount < max) return setTimeout(coffee, 1000)
  53. t.equal(err.length, 1, 'coffee editor shows one error')
  54. t.equal(err.line, '5', 'on line 5')
  55. }()
  56. +function json() {
  57. var err = getError('json')
  58. if (!err.length && ++jsonCount < max) return setTimeout(json, 1000)
  59. t.equal(err.length, 1, 'json editor shows one error')
  60. t.equal(err.line, '5', 'on line 5')
  61. }()
  62. +function lua() {
  63. var err = getError('lua')
  64. if (!err.length && ++luaCount < max) return setTimeout(lua, 1000)
  65. t.equal(err.length, 1, 'lua editor shows one error')
  66. t.equal(err.line, '6', 'on line 6')
  67. t.end()
  68. }()
  69. +function xml() {
  70. var err = getError('xml')
  71. if (!err.length && ++xmlCount < max) return setTimeout(xml, 1000)
  72. t.equal(err.length, 1, 'xml editor shows one error')
  73. t.equal(err.line, '5', 'on line 5')
  74. }()
  75. })