Skip to content

Commit 6a29cbe

Browse files
authored
fix: require bug and sampler bug (#177)
* The object destructured require statements where incorrect * The sampler looked for objects instead of classes (when creating methods)
1 parent a1ee7fe commit 6a29cbe

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

libraries/search-javascript/lib/testbuilding/ContextBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class ContextBuilder {
9090
let variableName = statement.name;
9191

9292
variableName =
93-
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(
93+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_".includes(
9494
variableName[0]
9595
)
9696
? variableName[0].toLowerCase() + variableName.slice(1)

libraries/search-javascript/lib/testbuilding/JavaScriptDecoder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ export class JavaScriptDecoder implements Decoder<JavaScriptTestCase, string> {
101101

102102
if (requires.length > 0) {
103103
beforeEachLines = [
104-
...requires.map((m) => `\tlet ${m.left};`),
104+
...requires.map(
105+
(m) =>
106+
`\tlet ${(m.left.includes(":") ? m.left.split(":")[1] : m.left)
107+
.replace("{", "")
108+
.replace("}", "")};`
109+
),
105110
`\tbeforeEach(() => {`,
106111
"\t\t// This is a hack to force the require cache to be emptied",
107112
"\t\t// Without this we would be using the same required object for each test",
@@ -112,7 +117,7 @@ export class JavaScriptDecoder implements Decoder<JavaScriptTestCase, string> {
112117
"require.resolve"
113118
)}];`
114119
),
115-
...requires.map((m) => `\t\t${m.left} = ${m.right}`),
120+
...requires.map((m) => `\t\t(${m.left} = ${m.right});`),
116121
`\t});`,
117122
"",
118123
];
@@ -125,7 +130,7 @@ export class JavaScriptDecoder implements Decoder<JavaScriptTestCase, string> {
125130
`describe('${targetName}', function() {`,
126131
...beforeEachLines,
127132
...tests.flatMap((testLines: string[], index) => [
128-
`\tit("Test ${index} for '${targetName}'", async () => {`,
133+
`\tit("Test ${index + 1} for '${targetName}'", async () => {`,
129134
...testLines.map((line) => `\t\t${line}`),
130135
index === tests.length - 1 ? "\t})" : "\t})\n",
131136
]),

libraries/search-javascript/lib/testcase/sampling/JavaScriptRandomSampler.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
325325
.filter((target) =>
326326
isExported(
327327
targets.find(
328-
(objectTarget) =>
329-
objectTarget.id === (<ObjectFunctionTarget>target).objectId
328+
(objectTarget) => objectTarget.id === (<MethodTarget>target).classId
330329
)
331330
)
332331
);
@@ -353,8 +352,7 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
353352
.filter((target) =>
354353
isExported(
355354
targets.find(
356-
(objectTarget) =>
357-
objectTarget.id === (<ObjectFunctionTarget>target).objectId
355+
(objectTarget) => objectTarget.id === (<MethodTarget>target).classId
358356
)
359357
)
360358
);
@@ -381,8 +379,7 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
381379
.filter((target) =>
382380
isExported(
383381
targets.find(
384-
(objectTarget) =>
385-
objectTarget.id === (<ObjectFunctionTarget>target).objectId
382+
(objectTarget) => objectTarget.id === (<MethodTarget>target).classId
386383
)
387384
)
388385
);

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)