From 12d2ae86431523c7d912b467ba046ed43d18a11c Mon Sep 17 00:00:00 2001 From: Vincent Bel Date: Thu, 31 Aug 2017 06:51:48 +0800 Subject: [PATCH] Remove duplicated tests in gatsby-remark-prismjs (#1965) --- .../__snapshots__/highlight-code.js.snap | 4 +- .../src/__tests__/highlight-code.js | 86 ++++--------------- .../src/__tests__/parse-line-number-range.js | 6 ++ 3 files changed, 27 insertions(+), 69 deletions(-) diff --git a/packages/gatsby-remark-prismjs/src/__tests__/__snapshots__/highlight-code.js.snap b/packages/gatsby-remark-prismjs/src/__tests__/__snapshots__/highlight-code.js.snap index 967a967dde641..1570d1bf44578 100644 --- a/packages/gatsby-remark-prismjs/src/__tests__/__snapshots__/highlight-code.js.snap +++ b/packages/gatsby-remark-prismjs/src/__tests__/__snapshots__/highlight-code.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`highlight code and lines with PrismJS highlights code for language cpp 1`] = ` +exports[`highlight code and lines with PrismJS for language cpp 1`] = ` " int sum(a, b) { return a + b; @@ -9,7 +9,7 @@ exports[`highlight code and lines with PrismJS highlights code for language cpp " `; -exports[`highlight code and lines with PrismJS highlights code for language jsx 1`] = ` +exports[`highlight code and lines with PrismJS for language jsx 1`] = ` " import React from \\"react\\" diff --git a/packages/gatsby-remark-prismjs/src/__tests__/highlight-code.js b/packages/gatsby-remark-prismjs/src/__tests__/highlight-code.js index 69c59f8c7d6ee..23ded1c186486 100644 --- a/packages/gatsby-remark-prismjs/src/__tests__/highlight-code.js +++ b/packages/gatsby-remark-prismjs/src/__tests__/highlight-code.js @@ -1,74 +1,27 @@ -const parseLineNumberRange = require(`../parse-line-number-range`) - describe(`highlight code and lines with PrismJS`, () => { - it(`parses numeric ranges from the languages variable`, () => { - expect(parseLineNumberRange(`jsx{1,5,7-8}`).highlightLines).toEqual([ - 1, - 5, - 7, - 8, - ]) - expect(parseLineNumberRange(`javascript{7-8}`).highlightLines).toEqual([ - 7, - 8, - ]) - expect(parseLineNumberRange(`javascript{7..8}`).highlightLines).toEqual([ - 7, - 8, - ]) - expect(parseLineNumberRange(`javascript{2}`).highlightLines).toEqual([2]) - expect(parseLineNumberRange(`javascript{2,4-5}`).highlightLines).toEqual([ - 2, - 4, - 5, - ]) - }) - it(`ignores negative numbers`, () => { - expect(parseLineNumberRange(`jsx{-1,1,5,7-8}`).highlightLines).toEqual([ - 1, - 5, - 7, - 8, - ]) - expect(parseLineNumberRange(`jsx{-1..4}`).highlightLines).toEqual([ - 1, - 2, - 3, - 4, - ]) - }) - it(`handles bad inputs`, () => { - expect(parseLineNumberRange(`jsx{-1`).highlightLines).toEqual([]) - expect(parseLineNumberRange(`jsx{-1....`).highlightLines).toEqual([]) + afterEach(() => { + jest.resetModules() }) - it(`parses languages without ranges`, () => { - expect(parseLineNumberRange(`jsx`).splitLanguage).toEqual(`jsx`) - }) - - describe(`highlights code for language`, () => { - afterEach(() => { - jest.resetModules() - }) - it(`cpp`, () => { - const highlightCode = require(`../highlight-code`) - const language = `cpp` - const lineNumbersHighlight = [1, 2] - const code = ` + it(`for language cpp`, () => { + const highlightCode = require(`../highlight-code`) + const language = `cpp` + const lineNumbersHighlight = [1, 2] + const code = ` int sum(a, b) { return a + b; } ` - expect( - highlightCode(language, code, lineNumbersHighlight) - ).toMatchSnapshot() - }) + expect( + highlightCode(language, code, lineNumbersHighlight) + ).toMatchSnapshot() + }) - it(`jsx`, () => { - const highlightCode = require(`../highlight-code`) - const language = `jsx` - const lineNumbersHighlight = [12, 13, 15] - const code = ` + it(`for language jsx`, () => { + const highlightCode = require(`../highlight-code`) + const language = `jsx` + const lineNumbersHighlight = [12, 13, 15] + const code = ` import React from "react" class Counter extends React.Component { @@ -95,9 +48,8 @@ class Counter extends React.Component { export default Counter ` - expect( - highlightCode(language, code, lineNumbersHighlight) - ).toMatchSnapshot() - }) + expect( + highlightCode(language, code, lineNumbersHighlight) + ).toMatchSnapshot() }) }) diff --git a/packages/gatsby-remark-prismjs/src/__tests__/parse-line-number-range.js b/packages/gatsby-remark-prismjs/src/__tests__/parse-line-number-range.js index de39d52c8b554..fe2b9580b45fa 100644 --- a/packages/gatsby-remark-prismjs/src/__tests__/parse-line-number-range.js +++ b/packages/gatsby-remark-prismjs/src/__tests__/parse-line-number-range.js @@ -23,6 +23,7 @@ describe(`parses numeric ranges from the languages markdown code directive`, () 5, ]) }) + it(`ignores negative numbers`, () => { expect(parseLineNumberRange(`jsx{-1,1,5,7-8}`).highlightLines).toEqual([ 1, @@ -37,8 +38,13 @@ describe(`parses numeric ranges from the languages markdown code directive`, () 4, ]) }) + it(`handles bad inputs`, () => { expect(parseLineNumberRange(`jsx{-1`).highlightLines).toEqual([]) expect(parseLineNumberRange(`jsx{-1....`).highlightLines).toEqual([]) }) + + it(`parses languages without ranges`, () => { + expect(parseLineNumberRange(`jsx`).splitLanguage).toEqual(`jsx`) + }) })