diff --git a/.depcheckrc b/.depcheckrc index c356e86..185fbe2 100644 --- a/.depcheckrc +++ b/.depcheckrc @@ -2,5 +2,6 @@ ignores: [ '@swc-node/register', 'prettier-plugin-organize-imports', 'rimraf', - 'typescript' + 'typescript', + '@digicatapult/dtdl-parser' ] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c3a818..e5d44e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,4 +89,37 @@ jobs: id: get_version uses: digicatapult/check-version@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + 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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 310c8fb..00856e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ bin obj -build/ \ No newline at end of file +build/ +*.tgz \ No newline at end of file diff --git a/README.md b/README.md index 8b8c35d..5c8518a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 @@ -8,7 +8,7 @@ A library for parsing and validating (DTDL)[https://learn.microsoft.com/en-us/az ```sh // with npm -npm install @digicatapult/ui-component-library +npm install @digicatapult/dtdl-parser ``` ## Basic Usage @@ -16,7 +16,7 @@ npm install @digicatapult/ui-component-library Install dependencies ```javascript -import { parseDirectories, validateDirectories, getInterop } from "dtdl-parser" +import { parseDirectories, validateDirectories, getInterop } from "@digicatapult/dtdl-parser" const parser = await getInterop() diff --git a/package-lock.json b/package-lock.json index 0f18a7e..5ce675c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@digicatapult/dtdl-parser", - "version": "0.0.25", + "version": "0.0.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@digicatapult/dtdl-parser", - "version": "0.0.25", + "version": "0.0.26", "license": "Apache-2.0", "devDependencies": { "@eslint/eslintrc": "^3.1.0", diff --git a/package.json b/package.json index 5dd8ff1..735bba7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 42b6ef1..a86ffae 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -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', diff --git a/test/integration/package.test.ts b/test/integration/package.test.ts new file mode 100644 index 0000000..f9bd895 --- /dev/null +++ b/test/integration/package.test.ts @@ -0,0 +1,13 @@ +import { parseDirectories, getInterop } from '@digicatapult/dtdl-parser' +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 () => { + const parser = await getInterop() + it('parser to function as expected', () => { + const model = parseDirectories(fixturesFilepath, parser) + expect(model).to.equal(exampleModel) + }) + }) +}) \ No newline at end of file