File tree Expand file tree Collapse file tree 4 files changed +63
-8
lines changed Expand file tree Collapse file tree 4 files changed +63
-8
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,10 @@ let brushCounter = 0;
254
254
255
255
export default sh ;
256
256
export const registerBrush = brush => sh . brushes [ 'brush' + brushCounter ++ ] = brush . default || brush ;
257
+ export const clearRegisteredBrushes = ( ) => {
258
+ sh . brushes = { } ;
259
+ brushCounter = 0 ;
260
+ }
257
261
258
262
/* an EJS hook for `gulp build --brushes` command
259
263
* <%- registerBrushes %>
Original file line number Diff line number Diff line change
1
+ import sizzle from 'sizzle' ;
2
+ import { expect } from 'chai' ;
3
+ import SyntaxHighlighter , { registerBrush , clearRegisteredBrushes } from '../..' ;
4
+ import Brush from '../fixtures/test_brush_v4' ;
5
+
6
+ function setupSyntaxHighlighter ( html ) {
7
+ let div ;
8
+
9
+ before ( done => {
10
+ registerBrush ( Brush ) ;
11
+
12
+ div = document . createElement ( 'div' ) ;
13
+ div . innerHTML = html ;
14
+ document . body . appendChild ( div ) ;
15
+
16
+ SyntaxHighlighter . highlight ( { gutter : false } ) ;
17
+
18
+ function wait ( ) {
19
+ if ( sizzle ( '.syntaxhighlighter' ) . length ) {
20
+ done ( ) ;
21
+ } else {
22
+ setTimeout ( wait , 900 ) ;
23
+ }
24
+ }
25
+
26
+ wait ( ) ;
27
+ } ) ;
28
+
29
+ after ( ( ) => {
30
+ clearRegisteredBrushes ( ) ;
31
+ document . body . removeChild ( div ) ;
32
+ } ) ;
33
+ }
34
+
35
+ describe ( 'integration/commonjs' , ( ) => {
36
+ describe ( 'first render pass' , ( ) => {
37
+ setupSyntaxHighlighter ( `<pre class="brush: test_brush_v4;">first</pre>` ) ;
38
+ it ( 'has applied the brush' , ( ) => expect ( sizzle ( '.syntaxhighlighter' ) [ 0 ] . innerHTML ) . to . contain ( `<code class="test_brush_v4 plain">first</code>` ) ) ;
39
+ it ( 'does not render gutter' , ( ) => expect ( sizzle ( '.syntaxhighlighter td.gutter' ) . length ) . to . equal ( 0 ) ) ;
40
+ } ) ;
41
+
42
+ describe ( 'second render pass' , ( ) => {
43
+ setupSyntaxHighlighter ( `<pre class="brush: test_brush_v4;">second</pre>` ) ;
44
+ it ( 'has applied the brush' , ( ) => expect ( sizzle ( '.syntaxhighlighter' ) [ 0 ] . innerHTML ) . to . contain ( `<code class="test_brush_v4 plain">second</code>` ) ) ;
45
+ } ) ;
46
+ } ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = function (config) {
8
8
included : false ,
9
9
} ,
10
10
'tests/integration/no-compat.test.js' ,
11
+ 'tests/integration/commonjs.test.js' ,
11
12
] ;
12
13
13
14
config . set ( opts ) ;
Original file line number Diff line number Diff line change 1
1
import { expect } from 'chai' ;
2
2
import Brush from '../fixtures/test_brush_v4' ;
3
3
4
- describe ( 'unit/commonjs' , function ( ) {
5
- let brush ;
4
+ describe ( 'unit/commonjs' , ( ) => {
6
5
let html ;
7
6
8
- before ( function ( ) {
9
- brush = new Brush ( ) ;
10
- html = brush . getHtml ( 'hello foo bar world!' ) ;
11
- } ) ;
7
+ describe ( 'using a brush' , ( ) => {
8
+ let brush ;
9
+
10
+ before ( ( ) => {
11
+ brush = new Brush ( ) ;
12
+ html = brush . getHtml ( 'hello foo bar world!' , { gutter : false } ) ;
13
+ } ) ;
12
14
13
- it ( 'returns html' , ( ) => expect ( html ) . to . be . ok ) ;
14
- it ( 'renders content' , ( ) => expect ( html ) . to . contain ( '<div class="line number1 index0 alt2"><code class="keyword">hello</code> <code class="plain">foo bar </code><code class="keyword">world</code><code class="plain">!</code></div>' ) ) ;
15
+ it ( 'returns html' , ( ) => expect ( html ) . to . be . ok ) ;
16
+ it ( 'renders content' , ( ) => expect ( html ) . to . contain ( '<div class="line number1 index0 alt2"><code class="keyword">hello</code> <code class="plain">foo bar </code><code class="keyword">world</code><code class="plain">!</code></div>' ) ) ;
17
+ it ( 'does not render gutter' , ( ) => expect ( html ) . to . not . contain ( 'class="gutter' ) ) ;
18
+ } ) ;
15
19
} ) ;
You can’t perform that action at this time.
0 commit comments