howtheysre

Форк
0
/
main.spec.js 
69 строк · 2.2 Кб
1
const fs = require('fs');
2
const chai = require('chai');
3

4
chai.use(require('chai-arrays'));
5
chai.use(require('chai-string'));
6

7
const expect = chai.expect;
8

9
const srcMd = fs.readFileSync('../README.md', 'utf8');
10

11
describe('Checklist', function() {
12
  describe('Header', function() {
13
    it('is intact', function() {
14
      expect(srcMd).to.startsWith('# How they SRE');
15
    });
16
  });
17

18
  describe('Section Headers', function() {
19
    it('intact', function() {
20
      const expectedH2List = [
21
        '## Introduction',
22
        '## Organizations',
23
        '## SRECon Mix Playlist',
24
        '## Resources',
25
        '## Credits',
26
        '## Other How They... repos',
27
        '## Contributors',
28
        '## Contribute',
29
        '## Stargazers Over Time',
30
        '## License'];
31
      const actualList = srcMd.match(/^## (.*$)/gim);
32
      expect(actualList).to.equalTo(expectedH2List);
33
    });
34
  });
35

36
  describe('Organization list', function() {
37
    it('is sorted', function() {
38
      const orgList = srcMd.match(/(?<=<summary>)(.*?)(?=<\/summary>)/g);
39
      expect(orgList).to.be.sorted(Intl.Collator().compare);
40
    });
41
  });
42

43
  describe('Uniqueness', function() {
44
    it('has unique items', function() {
45
      const items = srcMd.match(/(?<=\* )(.*?)(?=\))/g);
46
      const hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);
47
      expect(hasDuplicate).to.equal(false, 'List has duplicate items');
48
    });
49
    it('has unique link text', function() {
50
      const items = srcMd.match(/(?<=\* \[)(.*?)(?=\])/g);
51
      const hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);
52
      expect(hasDuplicate).to.equal(false, 'List has duplicate text');
53
    });
54
    it('has unique urls', function() {
55
      const items = srcMd.match(/(?<=\* \[*.*\]\()(.*?)(?=\))/g);
56
      // this link appears twice hence filtering it
57
      const filteredItems = arrayRemove(items, 'https://github.com/abhivaikar/howtheytest');
58
      const hasDuplicate = filteredItems
59
          .some((val, i) => filteredItems.indexOf(val) !== i);
60
      expect(hasDuplicate).to.equal(false, 'List has duplicate link');
61
    });
62
  });
63
});
64

65
function arrayRemove(arr, value) {
66
  return arr.filter(function(ele) {
67
    return ele != value;
68
  });
69
}
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.