@@ -49,7 +49,7 @@ describe("doctorService", () => {
4949 filesContents : {
5050 file1 : 'const application = require("application");'
5151 } ,
52- expectedShortImports : [ { file : "file1" , line : 'const application = require("application"); ' } ]
52+ expectedShortImports : [ { file : "file1" , line : 'const application = require("application")' } ]
5353 } ,
5454 {
5555 filesContents : {
@@ -61,7 +61,7 @@ describe("doctorService", () => {
6161 filesContents : {
6262 file1 : 'const Observable = require("data/observable").Observable;'
6363 } ,
64- expectedShortImports : [ { file : "file1" , line : 'const Observable = require("data/observable").Observable; ' } ]
64+ expectedShortImports : [ { file : "file1" , line : 'const Observable = require("data/observable").Observable' } ]
6565 } ,
6666 {
6767 filesContents : {
@@ -73,7 +73,7 @@ describe("doctorService", () => {
7373 filesContents : {
7474 file1 : 'import * as application from "application";'
7575 } ,
76- expectedShortImports : [ { file : "file1" , line : 'import * as application from "application"; ' } ]
76+ expectedShortImports : [ { file : "file1" , line : 'import * as application from "application"' } ]
7777 } ,
7878 {
7979 filesContents : {
@@ -85,7 +85,7 @@ describe("doctorService", () => {
8585 filesContents : {
8686 file1 : 'import { run } from "application";'
8787 } ,
88- expectedShortImports : [ { file : "file1" , line : 'import { run } from "application"; ' } ]
88+ expectedShortImports : [ { file : "file1" , line : 'import { run } from "application"' } ]
8989 } ,
9090 {
9191 filesContents : {
@@ -98,7 +98,7 @@ describe("doctorService", () => {
9898 filesContents : {
9999 file1 : "import { run } from 'application';"
100100 } ,
101- expectedShortImports : [ { file : "file1" , line : "import { run } from 'application'; " } ]
101+ expectedShortImports : [ { file : "file1" , line : "import { run } from 'application'" } ]
102102 } ,
103103 {
104104 // Using single quotes
@@ -114,8 +114,8 @@ const Observable = require("data/observable").Observable;
114114`
115115 } ,
116116 expectedShortImports : [
117- { file : "file1" , line : 'const application = require("application"); ' } ,
118- { file : "file1" , line : 'const Observable = require("data/observable").Observable; ' } ,
117+ { file : "file1" , line : 'const application = require("application")' } ,
118+ { file : "file1" , line : 'const Observable = require("data/observable").Observable' } ,
119119 ]
120120 } ,
121121 {
@@ -125,7 +125,7 @@ const Observable = require("tns-core-modules/data/observable").Observable;
125125`
126126 } ,
127127 expectedShortImports : [
128- { file : "file1" , line : 'const application = require("application"); ' } ,
128+ { file : "file1" , line : 'const application = require("application")' } ,
129129 ]
130130 } ,
131131 {
@@ -137,8 +137,8 @@ const Observable = require("tns-core-modules/data/observable").Observable;
137137const Observable = require("data/observable").Observable;`
138138 } ,
139139 expectedShortImports : [
140- { file : "file1" , line : 'const application = require("application"); ' } ,
141- { file : "file2" , line : 'const Observable = require("data/observable").Observable;' } ,
140+ { file : "file1" , line : 'const application = require("application")' } ,
141+ { file : "file2" , line : 'const Observable = require("data/observable").Observable' } ,
142142 ]
143143 } ,
144144 {
@@ -150,7 +150,45 @@ const Observable = require("tns-core-modules/data/observable").Observable;
150150 file2 : `const application = require("some-name-tns-core-modules-widgets/application");
151151const Observable = require("tns-core-modules-widgets/data/observable").Observable;`
152152 } ,
153- expectedShortImports : [ ]
153+ expectedShortImports : [ ]
154+ } ,
155+ {
156+ filesContents : {
157+ // several statements on one line
158+ file1 : 'const _ = require("lodash");console.log("application");'
159+ } ,
160+ expectedShortImports : [ ]
161+ } ,
162+ {
163+ filesContents : {
164+ // several statements on one line with actual short imports
165+ file1 : 'const _ = require("lodash");const application = require("application");console.log("application");' ,
166+ file2 : 'const _ = require("lodash");const application = require("application");const Observable = require("data/observable").Observable;'
167+ } ,
168+ expectedShortImports : [
169+ { file : "file1" , line : 'const application = require("application")' } ,
170+ { file : "file2" , line : 'const application = require("application")' } ,
171+ { file : "file2" , line : 'const Observable = require("data/observable").Observable' } ,
172+ ]
173+ } ,
174+ {
175+ filesContents : {
176+ // several statements on one line withoutshort imports
177+ file1 : 'const _ = require("lodash");const application = require("tns-core-modules/application");console.log("application");' ,
178+ file2 : 'const _ = require("lodash");const application = require("tns-core-modules/application");const Observable = require("tns-core-modules/data/observable").Observable;'
179+ } ,
180+ expectedShortImports : [ ]
181+ } ,
182+ {
183+ // Incorrect behavior, currently by design
184+ // In case you have a multiline string and one of the lines matches our RegExp we'll detect it as short import
185+ filesContents : {
186+ file1 : 'const _ = require("lodash");const application = require("application");console.log("application");console.log(`this is line\nyou should import some long words here "application" module and other words here`)' ,
187+ } ,
188+ expectedShortImports : [
189+ { file : "file1" , line : 'const application = require("application")' } ,
190+ { file : "file1" , line : 'you should import some long words here "application" module and other words here`)' } ,
191+ ]
154192 } ,
155193 ] ;
156194
0 commit comments