Skip to content

Commit

Permalink
✅ transitive dependencies test added (direct and indirect)
Browse files Browse the repository at this point in the history
  • Loading branch information
noyshabtay committed Nov 23, 2023
1 parent 9d3788e commit 9c331c5
Show file tree
Hide file tree
Showing 8 changed files with 1,902 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/test/java/com/jfrog/ide/common/yarn/YarnTreeBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class YarnTreeBuilderTest {

enum Project {
EMPTY("package-name1", "empty"),
DEPENDENCY("package-name2", "dependency");
DEPENDENCY("package-name2", "dependency"),
EXAMPLE("example-yarn-package", "exampleYarnPackage");

private final String name;
private final Path path;
Expand Down Expand Up @@ -158,6 +159,14 @@ public void extractMultiplePathsTest() {
private Object[][] findDependencyImpactPathsProvider() {
return new Object[][]{
{Project.DEPENDENCY, "@types/node", Set.of("14.14.10"), List.of(List.of("package-name2", "@types/node:14.14.10"))},
{Project.EXAMPLE, "lodash", Set.of("4.16.2"), List.of(List.of("example-yarn-package", "lodash:4.16.2"),
List.of("example-yarn-package", "jest-cli", "jest-runtime", "babel-core", "lodash:4.16.2"),
List.of("example-yarn-package", "jest-cli", "jest-runtime", "babel-core", "babel-register", "lodash:4.16.2"),
List.of("example-yarn-package", "jest-cli", "istanbul-lib-instrument", "babel-generator", "lodash:4.16.2"),
List.of("example-yarn-package", "jest-cli", "istanbul-lib-instrument", "babel-template", "lodash:4.16.2"),
List.of("example-yarn-package", "jest-cli", "istanbul-lib-instrument", "babel-traverse", "lodash:4.16.2"),
List.of("example-yarn-package", "jest-cli", "istanbul-lib-instrument", "babel-types", "lodash:4.16.2")
)},
};
}

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/yarn/exampleYarnPackage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
26 changes: 26 additions & 0 deletions src/test/resources/yarn/exampleYarnPackage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BSD License

For Yarn software

Copyright (c) 2016-present, Yarn Contributors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 changes: 83 additions & 0 deletions src/test/resources/yarn/exampleYarnPackage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
This is an example package that can be used to test Yarn.

It has the common default fields in its `package.json`, along with production and development dependencies as well that
are specific to the package we have created.

## The `package.json`

### Default Package Fields

`yarn init` produces a default `package.json` similar to:

```
{
"name": "example-yarn-package",
"version": "1.0.0",
"description": "An example package to demonstrate Yarn",
"main": "index.js",
"repository": {
"url": "github.com/yarnpkg/example-yarn-package",
"type": "git"
},
"author": "Yarn Contributors",
"license": "BSD-2-Clause",
}
```

### Custom Package Fields

You can add custom fields to your `package.json` as well. In our case, we have added 4 custom fields.

The `scripts` field are for any special scripts that you want to use when running `yarn`. For example, here we add a
script called `test` that calls the Jest test runner because we added Jest tests to our Yarn package.

```
"scripts": {
"test": "jest"
},
```

The `dependencies` field lists the other packages that this package is dependent upon. Our example package is dependent
on [Lodash](https://lodash.com/) since we use its `multiply` function.

```
"dependencies": {
"lodash": "^4.16.2"
},
```

The `devDependencies` field lists the other packages that this package is dependent upon *during development*. Our
example package is dependent on [Jest](https://facebook.github.io/jest/) since we created some Jest-enabled tests for
our package.

```
"devDependencies": {
"jest-cli": "15.1.1"
},
```

The `jest` field is a custom field specific to the Jest package we included as a dev dependency. In this case, we are
testing
in a node environment at the command-line.

```
"jest": {
"testEnvironment": "node"
}
```

> It is important to note that Lodash and Jest are not required for Yarn. They are just examples of what can be used
> when you are creating the code for your Yarn package.
## Development

```
$ yarn install
$ yarn run test
```

## Production

```
$ yarn install --production
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

test('area of rectangle with width 3 and height 4 to equal 12', () => {
const ShapeMath = require('../index.js');
expect(ShapeMath.area_rectangle(3, 4)).toBe(12);
})
14 changes: 14 additions & 0 deletions src/test/resources/yarn/exampleYarnPackage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Math functions on shapes
*/

'use strict';

// For package depenency demonstration purposes only
var multiply = require('lodash/multiply');

module.exports = {
area_rectangle: function (width, height) {
return multiply(height, width);
}
}
24 changes: 24 additions & 0 deletions src/test/resources/yarn/exampleYarnPackage/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "example-yarn-package",
"version": "1.0.0",
"description": "An example package to demonstrate Yarn",
"main": "index.js",
"repository": {
"url": "github.com/yarnpkg/example-yarn-package",
"type": "git"
},
"scripts": {
"test": "jest"
},
"author": "Yarn Contributors",
"license": "BSD-2-Clause",
"dependencies": {
"lodash": "4.16.2"
},
"devDependencies": {
"jest-cli": "15.1.1"
},
"jest": {
"testEnvironment": "node"
}
}
Loading

0 comments on commit 9c331c5

Please sign in to comment.