From 269e538b8b1921d2cac526daf89733d1a759d4aa Mon Sep 17 00:00:00 2001 From: djm <35852337+dmaccormack@users.noreply.github.com> Date: Fri, 11 Nov 2022 10:03:53 -0500 Subject: [PATCH] test: Add a simple typescript integration test --- .gitattributes | 1 + itest/es6-ts/.gitignore | 5 ++ itest/es6-ts/main.ts | 19 +++++++ itest/es6-ts/package-lock.json | 90 ++++++++++++++++++++++++++++++++++ itest/es6-ts/package.json | 26 ++++++++++ itest/es6-ts/tsconfig.json | 7 +++ itest/itest.sh | 5 ++ 7 files changed, 153 insertions(+) create mode 100644 itest/es6-ts/.gitignore create mode 100644 itest/es6-ts/main.ts create mode 100644 itest/es6-ts/package-lock.json create mode 100644 itest/es6-ts/package.json create mode 100644 itest/es6-ts/tsconfig.json diff --git a/.gitattributes b/.gitattributes index f096b52..d6c567a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,6 +6,7 @@ *.htm text diff=html eol=lf *.html text diff=html eol=lf *.js text eol=lf +*.ts text eol=lf *.mjs text eol=lf *.cjs text eol=lf *.json text eol=lf diff --git a/itest/es6-ts/.gitignore b/itest/es6-ts/.gitignore new file mode 100644 index 0000000..bab3296 --- /dev/null +++ b/itest/es6-ts/.gitignore @@ -0,0 +1,5 @@ + +# typescript generated +*.js +*.js.map + diff --git a/itest/es6-ts/main.ts b/itest/es6-ts/main.ts new file mode 100644 index 0000000..6ae546c --- /dev/null +++ b/itest/es6-ts/main.ts @@ -0,0 +1,19 @@ + +import JsonURL from "@jsonurl/jsonurl"; +import { readFileSync } from "fs"; +const pkg = JSON.parse(String(readFileSync("package.json"))); +const expected = "(hello:world)"; + +function assert(actual) { + if (actual !== expected) { + console.log( + pkg.description, + ": expected '" + expected + "' but received '" + actual + "'" + ); + + process.exit(1); + } +} + +assert(JsonURL.stringify(JsonURL.parse(expected))); + diff --git a/itest/es6-ts/package-lock.json b/itest/es6-ts/package-lock.json new file mode 100644 index 0000000..9b584a4 --- /dev/null +++ b/itest/es6-ts/package-lock.json @@ -0,0 +1,90 @@ +{ + "name": "@jsonurl/itest-es6-ts", + "version": "0.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@jsonurl/itest-es6-ts", + "version": "0.0.0", + "license": "MIT", + "dependencies": { + "@jsonurl/jsonurl": "file:../..", + "typescript": "^4.8.4" + } + }, + "../..": { + "name": "@jsonurl/jsonurl", + "version": "1.0.0-SNAPSHOT", + "license": "MIT", + "devDependencies": { + "@babel/cli": "^7.15.4", + "@babel/core": "^7.15.5", + "@babel/preset-env": "^7.15.4", + "@rollup/plugin-alias": "^4.0.0", + "@rollup/plugin-babel": "^6.0.0", + "@rollup/plugin-replace": "^5.0.0", + "babel-jest": "^29.2.0", + "editorconfig": "^1.0.0", + "eslint": "^8.25.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-jest": "^27.1.2", + "eslint-plugin-prettier": "^4.2.1", + "jest": "^29.2.0", + "jsdoc": "^4.0.0", + "prettier": "^2.7.1", + "rollup": "^2.56.3", + "rollup-plugin-eslint": "^7.0.0", + "rollup-plugin-terser": "^7.0.2", + "typescript": "^4.4.2" + } + }, + "node_modules/@jsonurl/jsonurl": { + "resolved": "../..", + "link": true + }, + "node_modules/typescript": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "@jsonurl/jsonurl": { + "version": "file:../..", + "requires": { + "@babel/cli": "^7.15.4", + "@babel/core": "^7.15.5", + "@babel/preset-env": "^7.15.4", + "@rollup/plugin-alias": "^4.0.0", + "@rollup/plugin-babel": "^6.0.0", + "@rollup/plugin-replace": "^5.0.0", + "babel-jest": "^29.2.0", + "editorconfig": "^1.0.0", + "eslint": "^8.25.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-jest": "^27.1.2", + "eslint-plugin-prettier": "^4.2.1", + "jest": "^29.2.0", + "jsdoc": "^4.0.0", + "prettier": "^2.7.1", + "rollup": "^2.56.3", + "rollup-plugin-eslint": "^7.0.0", + "rollup-plugin-terser": "^7.0.2", + "typescript": "^4.4.2" + } + }, + "typescript": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==" + } + } +} diff --git a/itest/es6-ts/package.json b/itest/es6-ts/package.json new file mode 100644 index 0000000..ad6b6b8 --- /dev/null +++ b/itest/es6-ts/package.json @@ -0,0 +1,26 @@ +{ + "name": "@jsonurl/itest-es6-ts", + "version": "0.0.0", + "private": true, + "description": "JSON->URL node ES6+Typescript integration test", + "main": "main.js", + "type": "module", + "scripts": { + "build": "npx tsc", + "test": "node ./" + }, + "author": "David MacCormack", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/jsonurl/jsonurl-js.git" + }, + "bugs": { + "url": "https://github.com/jsonurl/jsonurl-js/issues" + }, + "homepage": "https://www.jsonurl.org/", + "dependencies": { + "@jsonurl/jsonurl": "file:../..", + "typescript": "^4.8.4" + } +} diff --git a/itest/es6-ts/tsconfig.json b/itest/es6-ts/tsconfig.json new file mode 100644 index 0000000..36843ad --- /dev/null +++ b/itest/es6-ts/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "target": "es6", + "moduleResolution": "node", + "sourceMap": true + } +} \ No newline at end of file diff --git a/itest/itest.sh b/itest/itest.sh index 97fda8e..57bbf58 100755 --- a/itest/itest.sh +++ b/itest/itest.sh @@ -68,6 +68,9 @@ itest es6-babel || test_es6babel_status=1 test_jsdom_status=0 itest jsdom || test_jsdom_status=1 +test_es6ts_status=0 +itest es6-ts || test_es6ts_status=1 + # # This test depends on the version of node. # node < 11 : no support for native ES6 modules @@ -93,11 +96,13 @@ itest_status cjs $test_cjs_status itest_status es6-babel $test_es6babel_status itest_status es6-native $test_es6native_status itest_status jsdom $test_jsdom_status +itest_status es6-ts $test_es6ts_status itest_exit cjs $test_cjs_exit itest_exit es6-babel $test_es6babel_exit itest_exit es6-native $test_es6native_exit itest_exit jsdom $test_jsdom_exit +itest_exit es6-ts $test_es6ts_exit exit 0