<commit_before>const fs = require('fs')
const path = require('path')
const expect = require('chai').expect
const requireDir = require('require-dir')
const semver = require('semver')
const matter = require('gray-matter')
const marky = require('marky-markdown-lite')

describe('electron.atom.io', () => {
  describe('apps', () => {
    const apps = require(path.join(__dirname, '_data/apps.json'))
    const featured = require(path.join(__dirname, '_data/featured_apps.json'))

    it('has a JSON file full of app metadata', () => {
      expect(apps.length).to.be.above(240)
      apps.forEach(app => {
        expect(app.slug).to.exist
        expect(app.name).to.exist
        expect(app.description).to.exist
        expect(app.website).to.exist
        expect(app.icon).to.exist
        expect(fs.existsSync(path.join(__dirname, 'images/apps', app.icon))).to.equal(true)
      })
    })

    it('has a PNG image file for every app icon', () => {
      apps.forEach(app => {
        expect(app.icon).to.exist
        expect(fs.existsSync(path.join(__dirname, 'images/apps', app.icon))).to.equal(true)
      })
    })

    it('limits featured app count to 24', () => {
      expect(featured.length).to.equal(24)
    })
  })

  describe('docs', () => {
    it('rewrites relative links', () => {
      const doc = loadDoc('api/browser-window.md')
      expect(doc).to.include('[Main]({{site.baseurl}}/docs/glossary#main-process)')
    })

    it('properly handles multiple links on a single line', () => {
      const doc = loadDoc('api/clipboard.md')
      expect(doc).to.include('[Main]({{site.baseurl}}/docs/glossary#main-process)')
      expect(doc).to.include('[Renderer]({{site.baseurl}}/docs/glossary#renderer-process)')
    })

    it('leaves absolute links intact', () => {
      const $ = marky(loadDoc('api/browser-window.md'))
      const links = $('a').map((i, el) => $(el).attr('href')).get()
      const httpLinks = links.filter(link => link.startsWith('https://'))
      expect(httpLinks.length).to.be.above(3)
    })

    it('preserves fenced js code snippets', () => {
      const doc = loadDoc('api/clipboard.md')
      expect(doc).to.include('```javascript\n')
    })

    it('HTML-encodes pipe characters to avoid confusing the jekyll kramdown parser', () => {
      const doc = loadDoc('api/net.md')
      expect(doc).to.include('(Object &#124; String)')
    })

    it('adds a warning comment so people know to edit docs on the electron/electron repo', () => {
      const doc = loadDoc('api/browser-window.md')
      expect(doc).to.include('This file is generated automatically')
    })

    describe('frontmatter', () => {
      const frontmatter = matter(loadDoc('api/app.md')).data
      it('has a semver version', () => {
        expect(frontmatter.version).to.match(/^v\d\.\d\.\d/)
      })

      it('has a permalink', () => {
        expect(frontmatter.permalink).to.equal('/docs/api/app/')
      })

      it('has a category', () => {
        expect(frontmatter.category).to.equal('API')<commit_msg>Add test for fragment links<commit_after>const fs = require('fs')
const path = require('path')
const expect = require('chai').expect
const requireDir = require('require-dir')
const semver = require('semver')
const matter = require('gray-matter')
const marky = require('marky-markdown-lite')

describe('electron.atom.io', () => {
  describe('apps', () => {
    const apps = require(path.join(__dirname, '_data/apps.json'))
    const featured = require(path.join(__dirname, '_data/featured_apps.json'))

    it('has a JSON file full of app metadata', () => {
      expect(apps.length).to.be.above(240)
      apps.forEach(app => {
        expect(app.slug).to.exist
        expect(app.name).to.exist
        expect(app.description).to.exist
        expect(app.website).to.exist
        expect(app.icon).to.exist
        expect(fs.existsSync(path.join(__dirname, 'images/apps', app.icon))).to.equal(true)
      })
    })

    it('has a PNG image file for every app icon', () => {
      apps.forEach(app => {
        expect(app.icon).to.exist
        expect(fs.existsSync(path.join(__dirname, 'images/apps', app.icon))).to.equal(true)
      })
    })

    it('limits featured app count to 24', () => {
      expect(featured.length).to.equal(24)
    })
  })

  describe('docs', () => {
    it('rewrites relative links', () => {
      const doc = loadDoc('api/browser-window.md')
      expect(doc).to.include('[Main]({{site.baseurl}}/docs/glossary#main-process)')
    })

    it('properly handles multiple links on a single line', () => {
      const doc = loadDoc('api/clipboard.md')
      expect(doc).to.include('[Main]({{site.baseurl}}/docs/glossary#main-process)')
      expect(doc).to.include('[Renderer]({{site.baseurl}}/docs/glossary#renderer-process)')
    })

    it('leaves absolute links intact', () => {
      const $ = marky(loadDoc('api/browser-window.md'))
      const links = $('a').map((i, el) => $(el).attr('href')).get()
      const httpLinks = links.filter(link => link.startsWith('https://'))
      expect(httpLinks.length).to.be.above(3)
    })

    it('leaves fragment links intact', () => {
      const doc = loadDoc('api/menu-item.md')
      expect(doc).to.include('[roles](#roles)')
    })

    it('preserves fenced js code snippets', () => {
      const doc = loadDoc('api/clipboard.md')
      expect(doc).to.include('```javascript\n')
    })

    it('HTML-encodes pipe characters to avoid confusing the jekyll kramdown parser', () => {
      const doc = loadDoc('api/net.md')
      expect(doc).to.include('(Object &#124; String)')
    })

    it('adds a warning comment so people know to edit docs on the electron/electron repo', () => {
      const doc = loadDoc('api/browser-window.md')
      expect(doc).to.include('This file is generated automatically')
    })

    describe('frontmatter', () => {
      const frontmatter = matter(loadDoc('api/app.md')).data
      it('has a semver version', () => {
        expect(frontmatter.version).to.match(/^v\d\.\d\.\d/)
      })

      it('has a permalink', () => {
        expect(frontmatter.permalink).to.equal('/docs/api/app/')
      })

      it('has a category', () => {
        expect(frontmatter.category).to.equal('API')
{'fraction_non_alphanumeric': 0.1889763779527559, 'fraction_numerical': 0.0035352723766672025, 'mean_word_length': 3.083989501312336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7257131', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1954, 'n_words': 353}