howtheysre
69 строк · 2.2 Кб
1const fs = require('fs');2const chai = require('chai');3
4chai.use(require('chai-arrays'));5chai.use(require('chai-string'));6
7const expect = chai.expect;8
9const srcMd = fs.readFileSync('../README.md', 'utf8');10
11describe('Checklist', function() {12describe('Header', function() {13it('is intact', function() {14expect(srcMd).to.startsWith('# How they SRE');15});16});17
18describe('Section Headers', function() {19it('intact', function() {20const 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'];31const actualList = srcMd.match(/^## (.*$)/gim);32expect(actualList).to.equalTo(expectedH2List);33});34});35
36describe('Organization list', function() {37it('is sorted', function() {38const orgList = srcMd.match(/(?<=<summary>)(.*?)(?=<\/summary>)/g);39expect(orgList).to.be.sorted(Intl.Collator().compare);40});41});42
43describe('Uniqueness', function() {44it('has unique items', function() {45const items = srcMd.match(/(?<=\* )(.*?)(?=\))/g);46const hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);47expect(hasDuplicate).to.equal(false, 'List has duplicate items');48});49it('has unique link text', function() {50const items = srcMd.match(/(?<=\* \[)(.*?)(?=\])/g);51const hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);52expect(hasDuplicate).to.equal(false, 'List has duplicate text');53});54it('has unique urls', function() {55const items = srcMd.match(/(?<=\* \[*.*\]\()(.*?)(?=\))/g);56// this link appears twice hence filtering it57const filteredItems = arrayRemove(items, 'https://github.com/abhivaikar/howtheytest');58const hasDuplicate = filteredItems59.some((val, i) => filteredItems.indexOf(val) !== i);60expect(hasDuplicate).to.equal(false, 'List has duplicate link');61});62});63});64
65function arrayRemove(arr, value) {66return arr.filter(function(ele) {67return ele != value;68});69}
70