From 93cf9e082d88f0e88328c31610f9fa10dc9727c0 Mon Sep 17 00:00:00 2001 From: Tomer Figenblat Date: Mon, 19 Jun 2023 21:25:10 +0300 Subject: [PATCH] ci: added matrix to pr workflow temp comment out linting until we fix some issues Signed-off-by: Tomer Figenblat --- .github/workflows/pr.yml | 42 +++++++++----- .github/workflows/stage.yml | 6 ++ src/providers/java_maven.js | 2 +- test/index.test.js | 92 ------------------------------- test/providers/java_maven.test.js | 3 +- 5 files changed, 37 insertions(+), 108 deletions(-) delete mode 100644 test/index.test.js diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 4183030..697f3bb 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,41 +6,55 @@ on: branches: - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: test: runs-on: ubuntu-latest name: Lint and test project - permissions: - checks: write - contents: write - pull-requests: write + strategy: + matrix: + node: ['18', 'latest'] + env: + MAIN_NODE_VER: '18' steps: - name: Checkout sources uses: actions/checkout@v3 - - name: Install node 18 + - name: Install node ${{ matrix.node }} uses: actions/setup-node@v3 with: - node-version: '18' + node-version: ${{ matrix.node }} cache: npm + - name: Setup Java 17 + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + cache: maven + - name: Install project modules run: npm ci - name: Lint source files run: npm run lint - - name: Run unit tests and create coverage report - run: npm run tests:rep + - name: Run unit tests + run: npm run test + + - name: Compile project + run: npm run compile - name: Run integration tests working-directory: integration run: bash ./run_it.sh - - name: Report test results - if: always() - uses: dorny/test-reporter@v1.6.0 + - name: Upload coverage reports + if: ${{ matrix.node == env.MAIN_NODE_VER }} + uses: actions/upload-artifact@v3 with: - name: Unit Tests Run - path: unit-tests-result.json - reporter: mocha-json + name: coverage + path: ./coverage/coverage-final.json diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index 8b581df..df678a4 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -25,6 +25,12 @@ jobs: node-version: '18' cache: npm + - name: Setup Java 17 + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + - name: Install project modules run: npm ci diff --git a/src/providers/java_maven.js b/src/providers/java_maven.js index 5453ace..cd55b14 100644 --- a/src/providers/java_maven.js +++ b/src/providers/java_maven.js @@ -42,7 +42,7 @@ function provideStack(manifest) { * @param {string} data - content of pom.xml for component report * @returns {Provided} */ -function provideComponent(data) { // WIP +function provideComponent(data) { // eslint-disable-line return { ecosystem, content: 'WIP', diff --git a/test/index.test.js b/test/index.test.js deleted file mode 100644 index 1231b2b..0000000 --- a/test/index.test.js +++ /dev/null @@ -1,92 +0,0 @@ -import { beforeEach } from 'mocha' -import chai from 'chai' -import sinon from 'sinon' -import sinonChai from "sinon-chai"; - -const expect = chai.expect - -chai.use(sinonChai) - -suite.skip('testing the application starting point', () => { - let requestComponentFake // fake requestComponent function - will be used for sending request - let requestStackFake // fake stackAnalysis function - will be used for sending request - let analysisModuleDummy // fake analysis module - will include the above functions and rewired to the sut - - let fakeProvidedData // fake provided data that will be returned by both provideStack and provideComponent funcs - let provideComponentDataStub // stub provideComponent function - will provide fake component content for analysis - let provideStackDataStub // stub provideComponent function - will provide fake stack content for analysis - let providerDummy // dummy provider - will be rewired by the getProvider utility function - let providerModuleDummy // dummy provider module - will return the fake provider - - let sut // index module subject under test - - beforeEach(async () => { - // create fake functions used for sending analysis request - requestComponentFake = sinon.fake() - requestStackFake = sinon.fake() - // create a dummy analysis module using the above function fakes - analysisModuleDummy = { - requestComponent: requestComponentFake, - requestStack: requestStackFake - } - // create fake data that will be returned by both provideComponent and provideStack - fakeProvidedData = { - ecosystem: 'fake-ecosystem-for-manifest-type', - content: 'fake-content-for-send-to-backend', - contentType: 'type-of-fake-content' - } - // stub the provideComponent function to return the fake provided data - provideComponentDataStub = sinon.stub() - provideComponentDataStub.returns(fakeProvidedData) - // stub the provideStack function to return the fake provided data - provideStackDataStub = sinon.stub() - provideStackDataStub.returns(fakeProvidedData) - // create a dummy provider module using the above function fakes - providerDummy = { - provideComponent: provideComponentDataStub, - provideStack: provideStackDataStub - } - // stub the provider module dummy to return thr dummy provider - providerModuleDummy = sinon.stub() - providerModuleDummy.returns(providerDummy) - - // short circuit the fs module used for verifying manifests are accessible - let feModuleDummy = { - accessSync: sinon.fake(), - constants: { - R_OK: 999 - } - } - // short circuit verifying manifests are accessible - // mockImport('node:fs', {...feModuleDummy}) - // // rewire the analysis and provider modules with the dummy modules - // mockImport('#root/src/provider', providerModuleDummy) - // mockImport('#root/src/analysis', analysisModuleDummy) - // // instantiate the subject under test - // sut = reImport('#root/src/index.js') - }) - - test('invoking componentAnalysis should get a provider, provide data, and request analysis', async () => { - await sut.componentAnalysis('dummy.manifest', 'dummy-manifest-data') - - expect(providerModuleDummy).to.be.calledOnceWith('dummy.manifest') - expect(provideComponentDataStub).to.be.calledOnceWith('dummy-manifest-data') - expect(requestComponentFake).to.be.calledOnceWith(fakeProvidedData, sinon.match.string) - }) - - test('invoking stackAnalysis defaults to JSON should get a provider, provide data, and request analysis', async () => { - await sut.stackAnalysis('/path/to/dummy.manifest') - - expect(providerModuleDummy).to.be.calledOnceWith('/path/to/dummy.manifest') - expect(provideStackDataStub).to.be.calledOnceWith() - expect(requestStackFake).to.be.calledOnceWith(fakeProvidedData, sinon.match.string, false) - }) - - test('invoking stackAnalysis for HTML should get a provider, provide data, and request analysis', async () => { - await sut.stackAnalysis('/path/to/dummy.manifest', true) - - expect(providerModuleDummy).to.be.calledOnceWith('/path/to/dummy.manifest') - expect(provideStackDataStub).to.be.calledOnceWith() - expect(requestStackFake).to.be.calledOnceWith(fakeProvidedData, sinon.match.string, true) - }) -}) diff --git a/test/providers/java_maven.test.js b/test/providers/java_maven.test.js index 7cd2363..aded780 100644 --- a/test/providers/java_maven.test.js +++ b/test/providers/java_maven.test.js @@ -32,6 +32,7 @@ suite('testing the java-maven data provider', () => { contentType: 'text/vnd.graphviz', content: expectedGraph }) - }).timeout(5000) // these test cases takes ~2500-2700 ms each + // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case) + }).timeout(process.env.GITHUB_ACTIONS ? 20000 : 5000) }) })