Skip to content

Commit

Permalink
test: create ts projects using esm and cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusTheHun committed Apr 17, 2024
1 parent 380ce4b commit 6349c22
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 6 deletions.
6 changes: 3 additions & 3 deletions runtime/JavaScript/package-lock.json

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

6 changes: 3 additions & 3 deletions runtime/JavaScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
},
"scripts": {
"build": "webpack",
"test": "jasmine",
"test": "jasmine && npm run test:projects",
"test:projects": "bash test-projects.sh",
"coverage": "c8 jasmine",
"lint": "eslint src/antlr4/"
},
Expand All @@ -51,14 +52,13 @@
},
"exports": {
".": {
"types": "./src/antlr4/index.d.cts",
"node": {
"types": "./src/antlr4/index.d.ts",
"import": "./dist/antlr4.node.mjs",
"require": "./dist/antlr4.node.cjs",
"default": "./dist/antlr4.node.mjs"
},
"browser": {
"types": "./src/antlr4/index.d.ts",
"import": "./dist/antlr4.web.mjs",
"require": "./dist/antlr4.web.cjs",
"default": "./dist/antlr4.web.mjs"
Expand Down
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-cjs-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
5 changes: 5 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-cjs-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { CharStream } = require("antlr4");

const cs = new CharStream("OK");

console.log(cs.toString());
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-cjs-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "test-import-node-cjs-ts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "commonjs",
"scripts": {
"test": "bash test.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"antlr4": "file:../../../.."
},
"devDependencies": {
"typescript": "^5.4.3"
}
}
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-cjs-ts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

tsconfigFiles=(
"tsconfig.node.commonjs.json"
)

failure=0

for tsconfig in "${tsconfigFiles[@]}"; do
echo -n "$tsconfig "

./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
result=$(node ./tsOutput/index.js)
[[ $result == "OK" ]] && echo "OK"
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL runtime: $tsconfig"; }
done

exit $failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "commonjs",
"moduleResolution": "node"
},
"include": ["index.ts"],
}
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-esm-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
5 changes: 5 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-esm-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CharStream } from "antlr4";

const cs = new CharStream("OK");

console.log(cs.toString());
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-esm-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "test-import-node-esm-ts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "bash test.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"antlr4": "file:../../../.."
},
"devDependencies": {
"typescript": "^5.4.3"
}
}
19 changes: 19 additions & 0 deletions runtime/JavaScript/spec/imports/setups/node-esm-ts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

tsconfigFiles=(
"tsconfig.node16.json"
"tsconfig.bundler.es2022.json"
)

failure=0

for tsconfig in "${tsconfigFiles[@]}"; do
echo -n "$tsconfig "

./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
result=$(node ./tsOutput/index.js)
[[ $result == "OK" ]] && echo "OK"
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL runtime: $tsconfig"; }
done

exit $failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "es2022",
"moduleResolution": "bundler"
},
"include": ["index.ts"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["index.ts"],
}
6 changes: 6 additions & 0 deletions runtime/JavaScript/test-projects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

cd spec/imports/setups/node-esm-ts
npm run test
cd ../node-cjs-ts
npm run test

0 comments on commit 6349c22

Please sign in to comment.