File tree Expand file tree Collapse file tree 3 files changed +62
-1
lines changed
lib/source-loader/src/server Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
3
+ exports [` insertAfterImports addon-notes 1` ] = `
4
+ "import React from 'react';
5
+
6
+ import BaseButton from '../components/BaseButton';
7
+ import markdownNotes from './notes/notes.md';
8
+ INSERT
9
+
10
+ const markdownString = '...';"
11
+ ` ;
12
+
3
13
exports [` insertAfterImports imports 1` ] = `
4
14
"import foo;
5
15
import bar;
6
16
INSERT
7
17
whatever;"
8
18
` ;
9
19
20
+ exports [` insertAfterImports multi-line imports 1` ] = `
21
+ "import foo;
22
+ import {
23
+ bar
24
+ } from baz;
25
+ INSERT
26
+ whatever;"
27
+ ` ;
28
+
10
29
exports [` insertAfterImports no imports 1` ] = `
11
30
"INSERT
12
31
foo bar;
13
32
baz;"
14
33
` ;
34
+
35
+ exports [` insertAfterImports single-line imports 1` ] = `
36
+ "import foo;
37
+ import { bar } from baz;
38
+ INSERT
39
+ whatever;"
40
+ ` ;
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ export function insertAfterImports(insert, source) {
6
6
if ( start === - 1 ) {
7
7
start = 0 ;
8
8
} else {
9
+ if ( / i m p o r t \s + { / . test ( source . slice ( start + 1 , start + 10 ) ) ) {
10
+ start = source . indexOf ( '}' , start + 1 ) ;
11
+ }
9
12
start = 1 + source . indexOf ( '\n' , start + 1 ) ;
10
13
}
11
14
const imports = source . slice ( 0 , start ) ;
@@ -49,7 +52,7 @@ var __LOCAL_DEPENDENCIES__ = ${JSON.stringify(localDependencies)};
49
52
var __IDS_TO_FRAMEWORKS__ = ${ JSON . stringify ( idsToFrameworks ) } ;
50
53
/* eslint-enable no-unused-vars,@typescript-eslint/no-unused-vars */
51
54
` ;
52
- // const annotated = insertAfterImports(preamble, source);
55
+ // return insertAfterImports(preamble, source);
53
56
return `${ preamble } ${ source } ` ;
54
57
}
55
58
) ;
Original file line number Diff line number Diff line change @@ -19,4 +19,36 @@ whatever;
19
19
` . trim ( ) ;
20
20
expect ( insertAfterImports ( insert , hasImports ) ) . toMatchSnapshot ( ) ;
21
21
} ) ;
22
+
23
+ it ( 'single-line imports' , ( ) => {
24
+ const hasImports = `
25
+ import foo;
26
+ import { bar } from baz;
27
+ whatever;
28
+ ` . trim ( ) ;
29
+ expect ( insertAfterImports ( insert , hasImports ) ) . toMatchSnapshot ( ) ;
30
+ } ) ;
31
+
32
+ it ( 'multi-line imports' , ( ) => {
33
+ const hasImports = `
34
+ import foo;
35
+ import {
36
+ bar
37
+ } from baz;
38
+ whatever;
39
+ ` . trim ( ) ;
40
+ expect ( insertAfterImports ( insert , hasImports ) ) . toMatchSnapshot ( ) ;
41
+ } ) ;
42
+
43
+ it ( 'addon-notes' , ( ) => {
44
+ const notesStory = `
45
+ import React from 'react';
46
+
47
+ import BaseButton from '../components/BaseButton';
48
+ import markdownNotes from './notes/notes.md';
49
+
50
+ const markdownString = '...';
51
+ ` . trim ( ) ;
52
+ expect ( insertAfterImports ( insert , notesStory ) ) . toMatchSnapshot ( ) ;
53
+ } ) ;
22
54
} ) ;
You can’t perform that action at this time.
0 commit comments