Skip to content

Commit

Permalink
Update node from 14 to 20 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thilo-Acrolinx authored Jul 9, 2024
1 parent e1f8e12 commit 00b0d6a
Show file tree
Hide file tree
Showing 10 changed files with 1,067 additions and 1,010 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

27 changes: 0 additions & 27 deletions .eslintrc.json

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ on:
push:
branches: [main]
schedule:
- cron: '0 2 * * *' # Everyday at 2:00AM
- cron: '0 2 * * *'
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
env:
TEST_SERVER_URL: ${{ secrets.TEST_SERVER_URL }}
ACROLINX_API_TOKEN: ${{ secrets.ACROLINX_API_TOKEN }}
ACROLINX_DEV_SIGNATURE: ${{ secrets.ACROLINX_DEV_SIGNATURE}}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.JS
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 20

- name: Build And Run Tests
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ build/

# Eclipse
.project
.settings

tmp
**/.env
39 changes: 18 additions & 21 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { ContentFormat } from '@acrolinx/sdk';
import { AcrolinxSDKDemo } from '../src/main.js';
import { AcrolinxSDKDemo } from '../src/main';
import { uuid } from 'uuidv4';
import * as dotenv from 'dotenv';

describe('SDKDemo tests', () => {
// Token generated from the Acrolinx dashboard.
const accessToken = 'access-token';

// URL of the Acrolinx platform.
const acrolinxUrl = 'https://partner-dev.internal.acrolinx.sh';
dotenv.config();

// Unique signature provided by Acrolinx for the integration.
const clientSignature = 'SW50ZWdyYXRpb25EZXZlbG9wbWVudERlbW9Pbmx5';
describe('SDKDemo tests', () => {
const TEST_SERVER_URL = process.env.TEST_SERVER_URL;
const ACROLINX_API_TOKEN = process.env.ACROLINX_API_TOKEN;
const ACROLINX_DEV_SIGNATURE = process.env.ACROLINX_DEV_SIGNATURE;

it('test endpoint creation', () => {
const demo = new AcrolinxSDKDemo(acrolinxUrl, clientSignature);
const demo = new AcrolinxSDKDemo(TEST_SERVER_URL, ACROLINX_DEV_SIGNATURE);
const endpoint = demo.createEndpoint();
expect(endpoint).not.toBeNull();
});

it('test check request creation', () => {
const demo = new AcrolinxSDKDemo(acrolinxUrl, clientSignature);
const demo = new AcrolinxSDKDemo(TEST_SERVER_URL, ACROLINX_DEV_SIGNATURE);
const checkRequest = demo.createCheckRequest('gen.demo.' + uuid());

expect(checkRequest).not.toBeNull();
Expand All @@ -30,63 +28,62 @@ describe('SDKDemo tests', () => {
});

it('test running check', async () => {
const demo = new AcrolinxSDKDemo(acrolinxUrl, clientSignature);
const demo = new AcrolinxSDKDemo(TEST_SERVER_URL, ACROLINX_DEV_SIGNATURE);
const endpoint = demo.createEndpoint();
const checkRequest = demo.createCheckRequest('gen.demo.' + uuid());

const checkResult = await demo.checkWithAcrolinx(
endpoint,
checkRequest,
accessToken,
ACROLINX_API_TOKEN,
);
expect(checkResult).not.toBeNull();
expect(checkResult.quality.score).not.toBeNull();

console.log('Acrolinx Score: ' + checkResult.quality.score);
console.log('Scorecard Url: ' + checkResult.reports.scorecard.link);

const contentAnalysisDashboardLink = await demo.fetchContentAnalysisDashboardUrl(endpoint, accessToken, checkRequest.checkOptions.batchId);
const contentAnalysisDashboardLink = await demo.fetchContentAnalysisDashboardUrl(endpoint, ACROLINX_API_TOKEN, checkRequest.checkOptions.batchId);

expect(contentAnalysisDashboardLink).not.toBeNull();
console.log('Content Analysis Dashboard Link: ' + contentAnalysisDashboardLink);
});
}, 10_000);

it('test running check for word document', async () => {
const demo = new AcrolinxSDKDemo(acrolinxUrl, clientSignature);
const demo = new AcrolinxSDKDemo(TEST_SERVER_URL, ACROLINX_DEV_SIGNATURE);
const endpoint = demo.createEndpoint();
const checkRequest = demo.createWordCheckRequest('gen.demo.' + uuid());

const checkResult = await demo.checkWithAcrolinx(
endpoint,
checkRequest,
accessToken,
ACROLINX_API_TOKEN,
);
expect(checkResult).not.toBeNull();
expect(checkResult.quality.score).not.toBeNull();

console.log('Acrolinx Score: ' + checkResult.quality.score);
console.log('Scorecard Url: ' + checkResult.reports.scorecard.link);

const contentAnalysisDashboardLink = await demo.fetchContentAnalysisDashboardUrl(endpoint, accessToken, checkRequest.checkOptions.batchId);
const contentAnalysisDashboardLink = await demo.fetchContentAnalysisDashboardUrl(endpoint, ACROLINX_API_TOKEN, checkRequest.checkOptions.batchId);

expect(contentAnalysisDashboardLink).not.toBeNull();
console.log('Content Analysis Dashboard Link: ' + contentAnalysisDashboardLink);
});

it('test fetching platform capabilities', async () => {
const demo = new AcrolinxSDKDemo(acrolinxUrl, clientSignature);
const demo = new AcrolinxSDKDemo(TEST_SERVER_URL, ACROLINX_DEV_SIGNATURE);
const endpoint = demo.createEndpoint();

const capabilities = await demo.getPlatformCapabilities(
endpoint,
accessToken,
ACROLINX_API_TOKEN,
);
expect(capabilities).not.toBeNull();
expect(capabilities.contentFormats).not.toBeNull();

capabilities.contentFormats.forEach( (format: ContentFormat) => {
console.log('Format: ' + format.displayName + ' id: ' + format.id);
})

});
});
42 changes: 42 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const tsEslint = require('typescript-eslint');
const sonarjs = require('eslint-plugin-sonarjs');
const sourceTsFiles = ['src/**/*.ts'];

/**
* @type {import('eslint').Linter.FlatConfig[]}
*/
module.exports = [
...tsEslint.configs.recommendedTypeChecked.map((config) => ({
...config,
files: sourceTsFiles,
})),
{
files: sourceTsFiles,
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
},

plugins: {
sonarjs
},

rules: {
semi: 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-regexp-exec': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
},
},
];
59 changes: 42 additions & 17 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
export default {
testEnvironment: 'node',
preset: 'ts-jest/presets/default-esm',
globals: {
'ts-jest': {
useESM: true,
},
/*
* Copyright 2020-present Acrolinx GmbH
*
* 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.
*/

module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest',
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.(m)?js$': '$1',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(ts)$',
moduleFileExtensions: ['ts', 'js'],
coverageDirectory: 'tmp/coverage',
coverageReporters: ['cobertura', 'json', 'lcov', 'text'],
collectCoverageFrom: ['src/**/*'],
coverageThreshold: {
global: {
statements: 93.5,
branches: 81,
functions: 86,
lines: 93.7,
},
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(m)?ts$',
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/**/*.ts',
'src/**/*.mts',
'!src/**/*.d.ts',
'!src/**/*.d.mts',
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'tmp',
outputName: 'junit.xml',
},
],
],
};
testURL: 'http://localhost/',
};
Loading

0 comments on commit 00b0d6a

Please sign in to comment.