Skip to content

Commit 7784b5f

Browse files
committed
test: add more tests for loadString method and path related testcases
1 parent 9e7cb95 commit 7784b5f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/services/assets/handlers/dart.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,58 @@ describe('services', () => {
110110
);
111111
expect(inputs.length).toEqual(1);
112112
});
113+
114+
it('should detect loadString operations', () => {
115+
const inputs = new DartHandler().getInputs(
116+
'test.uri',
117+
'rootBundle.loadString("assets/data.json");'
118+
);
119+
expect(inputs.length).toEqual(1);
120+
expect(inputs[0]).toMatchObject({
121+
id: 'File Read - "assets/data.json"',
122+
type: 'data',
123+
path: '"assets/data.json"',
124+
});
125+
});
126+
127+
it('should detect file reads with fully qualified linux/macos paths', () => {
128+
const inputs = new DartHandler().getInputs(
129+
'test.uri',
130+
'File("/test/dir/test.txt").readAsStringSync();'
131+
);
132+
expect(inputs.length).toEqual(1);
133+
expect(inputs[0]).toMatchObject({
134+
id: 'File Read - "/test/dir/test.txt"',
135+
type: 'data',
136+
path: '"/test/dir/test.txt"',
137+
});
138+
});
139+
140+
it('should detect file reads with fully qualified windows paths', () => {
141+
const inputs = new DartHandler().getInputs(
142+
'test.uri',
143+
'File("C:\\\\test\\\\dir\\\\test.txt").readAsStringSync();'
144+
);
145+
expect(inputs.length).toEqual(1);
146+
expect(inputs[0]).toMatchObject({
147+
id: 'File Read - "C:\\\\test\\\\dir\\\\test.txt"',
148+
type: 'data',
149+
path: '"C:\\\\test\\\\dir\\\\test.txt"',
150+
});
151+
});
152+
153+
it('should detect file reads with relative paths', () => {
154+
const inputs = new DartHandler().getInputs(
155+
'test.uri',
156+
'File("../data/test.csv").readAsStringSync();'
157+
);
158+
expect(inputs.length).toEqual(1);
159+
expect(inputs[0]).toMatchObject({
160+
id: 'File Read - "../data/test.csv"',
161+
type: 'data',
162+
path: '"../data/test.csv"',
163+
});
164+
});
113165
});
114166

115167
describe('getOutputs', () => {

0 commit comments

Comments
 (0)