Skip to content

Commit

Permalink
added integration test
Browse files Browse the repository at this point in the history
integration test makes use of npm pack to mimic npm package release
  • Loading branch information
syedhasandigi committed Oct 25, 2024
1 parent 0ab31d4 commit d92f038
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ ignores: [
'@swc-node/register',
'prettier-plugin-organize-imports',
'rimraf',
'typescript'
'typescript',
'@digicatapult/dtdl-parser'
]
35 changes: 34 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,37 @@ jobs:
id: get_version
uses: digicatapult/check-version@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}

integration-tests:
name: Run Integration tests
needs: [check-version]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-verions: 20.x
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install wasm tools
run: dotnet workload install wasm-tools
- name: Install Packages
run: npm ci
- name: Build
run: npm run build
- name: build package
run: npm pack
- name: install built package
run: npm install digicatapult-dtdl-parser-${{ needs.check-version.outputs.version }}.tgz
- name: run integration tests
run: npm run test:integration
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
bin
obj
build/
build/
*.tgz
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# dtdl-parser library

A library for parsing and validating (DTDL)[https://learn.microsoft.com/en-us/azure/digital-twins/concepts-models] ontologies.
A library for parsing and validating [DTDL](https://learn.microsoft.com/en-us/azure/digital-twins/concepts-models) ontologies.

## Installation / Adding to the Package.json

`@digicatapult/dtdl-parser` are available as an [npm package](https://www.npmjs.com/package/@digicatapult/dtdl-parser). In order to use your local version in the project please use `npm link` more on it -> [here](https://docs.npmjs.com/cli/v10/commands/npm-link) and below in this document

```sh
// with npm
npm install @digicatapult/ui-component-library
npm install @digicatapult/dtdl-parser
```

## Basic Usage

Install dependencies

```javascript
import { parseDirectories, validateDirectories, getInterop } from "dtdl-parser"
import { parseDirectories, validateDirectories, getInterop } from "@digicatapult/dtdl-parser"


const parser = await getInterop()
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/dtdl-parser",
"version": "0.0.25",
"version": "0.0.26",
"description": "JS tool to parse DTDL defined Ontologies",
"main": "build/index.js",
"type": "module",
Expand All @@ -14,13 +14,16 @@
],
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/mocha --config ./test/mocharc.json ./src/**/*.test.ts",
"test:integration": "npm run build:package && NODE_ENV=test ./node_modules/.bin/mocha --config ./test/mocharc.json ./test/**/*.test.ts && npm run clean:package",
"build": "npm run build:ts && npm run interop:build && npm run build:declarations",
"build:declarations": "tsc --emitDeclarationOnly",
"build:package": "npm pack && npm install -g digicatapult-dtdl-parser-*.tgz",
"interop:debug": "dotnet build interop",
"interop:build": "dotnet build src/interop --configuration Release",
"build:ts": "swc ./src -d ./build --strip-leading-paths",
"check": "tsc --noEmit",
"clean": "rimraf -rf ./build",
"clean:package": "rimraf *.tgz && npm uninstall @digicatapult/dtdl-parser",
"lint": "eslint .",
"depcheck": "depcheck"
},
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import path from 'path'
import { parseDirectories, searchForJsonFiles, validateDirectories } from '../index'
import { Parser } from '../interop'

const fixturesFilepath = path.resolve('src/__tests__/fixtures')
export const fixturesFilepath = path.resolve('src/__tests__/fixtures')

const exampleModel = {
export const exampleModel = {
'dtmi:com:example:base;1': {
languageMajorVersion: 3,
Id: 'dtmi:com:example:base;1',
Expand Down
13 changes: 13 additions & 0 deletions test/integration/package.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { parseDirectories, getInterop } from '@digicatapult/dtdl-parser'

Check failure on line 1 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Replace `parseDirectories,·getInterop` with `getInterop,·parseDirectories`
import { expect } from 'chai'
import { exampleModel, fixturesFilepath } from '../../src/__tests__/index.test'

describe('integration test on build and package integrity', () => {
describe('parser to function as expected', async () => {

Check failure on line 6 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Delete `··`
const parser = await getInterop()

Check failure on line 7 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Replace `········` with `····`
it('parser to function as expected', () => {

Check failure on line 8 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Delete `····`
const model = parseDirectories(fixturesFilepath, parser)

Check failure on line 9 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Delete `······`
expect(model).to.equal(exampleModel)

Check failure on line 10 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Delete `······`
})

Check failure on line 11 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Delete `····`
})

Check failure on line 12 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Delete `··`
})

Check failure on line 13 in test/integration/package.test.ts

View workflow job for this annotation

GitHub Actions / Run Static Analysis Checks (lint)

Insert `⏎`

0 comments on commit d92f038

Please sign in to comment.