Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/missing tests #13

Merged
merged 13 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:

tests:
name: Run tests
strategy:
matrix:
command: ['test', 'test:integration']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -73,7 +76,7 @@ jobs:
- name: Install Packages
run: npm ci
- name: Run tests
run: npm run test
run: npm run ${{ matrix.command }}

check-version:
name: "Check version"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
command: ['test']
command: ['test', 'test:integration']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -89,4 +89,4 @@ jobs:
id: get_version
uses: digicatapult/check-version@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
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
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ export default [
},
},
{
ignores: ['build/', 'node_modules/', 'interop/'],
ignores: ['build/', 'node_modules/', 'src/interop/'],
},
]
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.

3 changes: 2 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,6 +14,7 @@
],
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/mocha --config ./test/mocharc.json ./src/**/*.test.ts",
"test:integration": "npm run build && NODE_ENV=test ./node_modules/.bin/mocha --config ./test/integration/mocharc.json ./test/**/*.test.js",
"build": "npm run build:ts && npm run interop:build && npm run build:declarations",
"build:declarations": "tsc --emitDeclarationOnly",
"interop:debug": "dotnet build interop",
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 = {
syedhasandigi marked this conversation as resolved.
Show resolved Hide resolved
'dtmi:com:example:base;1': {
languageMajorVersion: 3,
Id: 'dtmi:com:example:base;1',
Expand Down
4 changes: 4 additions & 0 deletions test/integration/mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"timeout": 5000,
"exit": true
}
63 changes: 63 additions & 0 deletions test/integration/package.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import path from 'node:path'
import { getInterop, parseDirectories } from '../../build/index.js'

const fixturesFilepath = path.resolve('dtdl/simple')

const emptyEntityProperties = {
SupplementalTypes: [],
SupplementalProperties: {},
UndefinedTypes: [],
UndefinedProperties: {},
description: {},
languageMajorVersion: 2,
displayName: {},
ChildOf: null,
DefinedIn: null,
}
const emptyInterfaceProperties = {
contents: {},
commands: {},
components: {},
properties: {},
relationships: {},
telemetries: {},
extendedBy: [],
extends: [],
schemas: [],
comment: null,
}

const exampleModel = {
'dtmi:com:example:base;1': {
...emptyEntityProperties,
...emptyInterfaceProperties,
languageMajorVersion: 3,
Id: 'dtmi:com:example:base;1',
ChildOf: 'dtmi:com:example;1',
DefinedIn: 'dtmi:com:example;1',
EntityKind: 'Interface',
ClassId: 'dtmi:dtdl:class:Interface;3',
extendedBy: ['dtmi:com:example;1'],
},
'dtmi:com:example;1': {
...emptyEntityProperties,
...emptyInterfaceProperties,
languageMajorVersion: 3,
Id: 'dtmi:com:example;1',
EntityKind: 'Interface',
ClassId: 'dtmi:dtdl:class:Interface;3',
extends: ['dtmi:com:example:base;1'],
},
}

describe('integration test on build and package integrity', () => {
describe('parser to function as expected', () => {
it('parser to function as expected', async () => {
const parser = await getInterop()
const model = parseDirectories(fixturesFilepath, parser)
expect(model).to.deep.equal(exampleModel)
})
})
})