Skip to content

Commit

Permalink
feat: prepare javascript code with new core version (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstallenberg committed May 25, 2023
1 parent 58cf717 commit 499c5b1
Show file tree
Hide file tree
Showing 172 changed files with 25,331 additions and 14,217 deletions.
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ syntest/
LICENSE*
Dockerfile
NOTICE
commitlint.config.js
link.sh


# The instrumentation files are copied from istanbul (and modified).
# In the future in a big refactor the instrumentation should be redone such that these files dont have to be ignored anymore.
**/instrumentation/Instrumenter.ts
**/instrumentation/VisitState.ts
**/instrumentation/Visitor.ts
**/instrumentation/Visitor.ts
**/instrumentation/source-coverage.ts
66 changes: 56 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,73 @@
{
"env": {
"es6": true,
"es2021": true,
"mocha": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
// "plugin:@typescript-eslint/recommended-requiring-type-checking", // TODO later too much work currently
"plugin:unicorn/recommended",
// "plugin:import/recommended", // TODO gives weird errors
"plugin:import/typescript",
"plugin:promise/recommended",
"prettier"//,
// "plugin:sonarjs/recommended" // TODO later too much work currently
],
"parser": "@typescript-eslint/parser",
// "parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
"ecmaVersion": 2021,
"sourceType": "module"//,
// "project": "./tsconfig.json",
// "tsconfigRootDir": "."
},
"plugins": ["@typescript-eslint", "notice"],
"settings": {
"import/resolver": {
"typescript": true,
"node": true
}
},
"plugins": [
"@typescript-eslint",
"notice",
"unused-imports"
],
"rules": {
"no-fallthrough": "off",
"notice/notice":["error",
// "import/first": "error",
// "import/newline-after-import": "error",
// "import/no-duplicates": "error",
// "import/order": ["error",
// {
// "alphabetize": {
// "order": "asc",
// "caseInsensitive": true
// },
// "newlines-between": "always"
// }
// ],
// "sort-imports": ["error",
// {
// "ignoreDeclarationSort": true,
// "ignoreCase": true
// }
// ],
"notice/notice": [
"error",
{
"templateFile": "./LICENSE.header.ts",
"nonMatchingTolerance": 0.8
}
]
}
],
"unicorn/filename-case": "off",
// "no-unused-vars": "off",
// "@typescript-eslint/no-unused-vars": "off",
// "unused-imports/no-unused-imports": "error",
// "unused-imports/no-unused-vars": [
// "error",
// { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
// ],
"no-fallthrough": "off",
"unicorn/expiring-todo-comments": "off"
}
}
7 changes: 4 additions & 3 deletions .github/workflows/main-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ jobs:
matrix:
# Collect coverage for all packages and plugins
package:
- libraries/ast-javascript
- libraries/cfg-javascript
- libraries/analysis-javascript
- libraries/ast-visitor-javascript
- libraries/instrumentation-javascript
- libraries/javascript
- libraries/search-javascript
- tools/javascript

steps:
# Download test results
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ jobs:
matrix:
# Collect coverage for all packages and plugins
package:
- libraries/ast-javascript
- libraries/cfg-javascript
- libraries/analysis-javascript
- libraries/ast-visitor-javascript
- libraries/instrumentation-javascript
- libraries/javascript
- libraries/search-javascript
- tools/javascript

steps:
# Download test results
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules/
.*
*.jpg
NOTICE
Dockerfile
Dockerfile
link.sh
69 changes: 32 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,62 @@ The common core contains the common interfaces for the code control-flow represe

#### NPM

The simplest way to use syntest-javascript is by installing the [npm package](https://www.npmjs.com/package/syntest/javascript).
The simplest way to use syntest javascript is by installing the following two npm packages: [@syntest/cli](https://www.npmjs.com/package/syntest/cli), [@syntest/javascript](https://www.npmjs.com/package/syntest/javascript).

```bash
$ npm install @syntest/cli
$ npm install @syntest/javascript
```

You can install it in your project as shown in the snippit above or you can install the package globally by using the npm options `-g`.

#### From source

The tool can be used by cloning the project, installing its dependencies, and compiling the TypeScript:

- Clone the projects
## Usage

```bash
$ git clone git@github.com:syntest-framework/syntest-javascript.git
```
To start you need to be in the root of the project folder containing the code you want to create test-cases for. Next, you need to install two dev-dependencies in your project, namely [chai](https://www.npmjs.com/package/chai) and [chai-as-promised](https://www.npmjs.com/package/chai-as-promised). Both are needed to run the tests.

- Install dependencies
Next, you want to run the following command:

```bash
$ cd syntest-javascript; npm install
$ npx syntest init config --modules @syntest/javascript
```

- Build Syntest-javascript
This will create the `.syntest.json` configuration file for you with some pre filled in parameters.
The file should look somewhat like this:

```bash
$ cd syntest-javascript; npm run build
```

You can create a `.syntest.js` file to change the way the tool behaves.

Finally run the tool

```bash
cd <PATH_TO_SYNTEST_JAVASCRIPT>; npm run standalone
{
...,
"target-root-directory": "./express",
"include": [
"./express/lib/**/*.js"
],
"exclude": [],
"modules": [
"@syntest/javascript"
],
"preset": "DynaMOSA"
...
}
```

The results can be found in the `syntest` folder

## Usage
In the above example the most important configuration options are shown.

To start you need to be in the root of the project folder containing the code you want to create test-cases for. Next, you need to install two dev-dependencies in your project, namely [chai](https://www.npmjs.com/package/chai) and [chai-as-promised](https://www.npmjs.com/package/chai-as-promised). Both are needed to run the tests.
- The preset value which decides the algorithms the tool will use.
- The loaded module "@syntest/javascript".
- The target root directory which is the source directory of all the files you want to target.
- The include array where you can specify which files to target.
- The exclude array where you can specify which files to exclude specifically

After installing these dependencies together with the tool, you can run the following example command.
Once these properties are set you can run:

```bash
$ syntest-javascript --target-root-directory="<PATH_TO_YOUR_SOURCE_FOLDER>/src" --total-time=10
$ npx syntest javascript test
```

This will test all javascript code that is contained in the source folder. It will run for 10 seconds.

SynTest-JavaScript is highly configurable and supports a bunch of options and arguments, all of them can be found by providing the `--help` option or `-h` for short. Another way of configuring the tool is by putting a .syntest.js file in the root of your project. The file should have the following structure:
If everything is correct the tool will now start.
The results can be found in the `syntest` folder

```js
module.exports = {
"population-size": 10,
"max-depth": 5,
...
}
```
SynTest-JavaScript is highly configurable and supports a bunch of options and arguments, all of them can be found by providing the `--help` option or `-h` for short. Another way of configuring the tool is through the .syntest.json file in the root of your project.

## Documentation

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions libraries/analysis-javascript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020-2023 Delft University of Technology and SynTest contributors
*
* This file is part of SynTest Framework - SynTest Javascript.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from "./lib/ast/AbstractSyntaxTreeFactory";
export * from "./lib/ast/defaultBabelConfig";

export * from "./lib/cfg/ControlFlowGraphFactory";
export * from "./lib/cfg/ControlFlowGraphVisitor";

export * from "./lib/dependency/DependencyFactory";
export * from "./lib/dependency/DependencyVisitor";

export * from "./lib/target/export/Export";
export * from "./lib/target/export/ExportDefaultDeclaration";
export * from "./lib/target/export/ExportFactory";
export * from "./lib/target/export/ExportNamedDeclaration";
export * from "./lib/target/export/ExportVisitor";
export * from "./lib/target/export/ExpressionStatement";

export * from "./lib/target/Target";
export * from "./lib/target/TargetFactory";
export * from "./lib/target/TargetVisitor";
export * from "./lib/target/VisibilityType";

export * from "./lib/type/discovery/element/Element";
export * from "./lib/type/discovery/element/ElementVisitor";

export * from "./lib/type/discovery/object/DiscoveredType";
export * from "./lib/type/discovery/object/ObjectVisitor";

export * from "./lib/type/discovery/relation/Relation";
export * from "./lib/type/discovery/relation/RelationVisitor";

export * from "./lib/type/discovery/TypeExtractor";

export * from "./lib/type/resolving/Type";
export * from "./lib/type/resolving/TypeEnum";
export * from "./lib/type/resolving/TypeModel";
export * from "./lib/type/resolving/TypeModelFactory";
export * from "./lib/type/resolving/InferenceTypeModelFactory";
export * from "./lib/type/resolving/RandomTypeModelFactory";

export * from "./lib/utils/fileSystem";

export * from "./lib/RootContext";
Loading

0 comments on commit 499c5b1

Please sign in to comment.