Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e38be5

Browse files
test: add example test
1 parent 8cc04a5 commit 1e38be5

File tree

12 files changed

+1303
-4
lines changed

12 files changed

+1303
-4
lines changed

‎package-lock.json‎

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SynTest Javascript
2+
Copyright 2020-2023 Delft University of Technology and SynTest contributors
3+
4+
This product includes software developed at
5+
Delft University of Technology (http://www.tudelft.nl/).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Abstract Syntax Tree Visitor library for JavaScript
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020-2023 Delft University of Technology and SynTest contributors
3+
*
4+
* This file is part of SynTest Framework - SynTest Javascript.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
export * from "./instrumentation/Instrumenter";
20+
export * from "./instrumentation/Visitor";
21+
export * from "./instrumentation/VisitState";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2020-2023 Delft University of Technology and SynTest contributors
3+
*
4+
* This file is part of SynTest Framework - SynTest Javascript.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import { TransformOptions, transformSync } from "@babel/core";
20+
import { Visitor } from "./Visitor";
21+
import { defaultBabelOptions } from "@syntest/ast-javascript";
22+
23+
export interface OutputObject {
24+
fileCoverage?: any;
25+
sourceMappingURL?: any;
26+
}
27+
28+
export class Instrumenter {
29+
async instrument(code: string, filename: string) {
30+
const options = JSON.parse(JSON.stringify(defaultBabelOptions));
31+
32+
let output: OutputObject = {};
33+
34+
options.filename = filename;
35+
options.plugins.push([
36+
({ types }) => {
37+
const ee = new Visitor(types, filename, {
38+
coverageVariable: "__coverage__",
39+
// reportLogic: opts.reportLogic,
40+
// coverageGlobalScope: opts.coverageGlobalScope,
41+
// coverageGlobalScopeFunc: opts.coverageGlobalScopeFunc,
42+
ignoreClassMethods: [],
43+
// inputSourceMap
44+
});
45+
46+
return {
47+
visitor: {
48+
Program: {
49+
enter: (path) => ee.enter(path),
50+
exit(path) {
51+
output = ee.exit(path);
52+
},
53+
},
54+
},
55+
};
56+
},
57+
]);
58+
59+
const codeMap = await transformSync(code, options);
60+
61+
if (!output || !output.fileCoverage) {
62+
return code;
63+
}
64+
65+
return codeMap.code;
66+
}
67+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /