-
Notifications
You must be signed in to change notification settings - Fork 74
160 lines (142 loc) · 5.18 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Test
on:
workflow_call:
jobs:
build-and-test-pull-request:
name: ${{ matrix.node }} ${{ matrix.target }} ${{ matrix.module }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node: [16.x, 18.x, 20.x, 22.x]
target: [es5, es2015, esnext]
module: [cjs, esm, umd]
include:
- {node: 16.x, target: ix}
- {node: 18.x, target: ix}
- {node: 20.x, target: ix}
- {node: 22.x, target: ix}
- {node: 22.x, target: src, args: --coverage}
steps:
- name: Setup node v${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "${{ matrix.node }}", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo targets_key='["${{ runner.os }}", "targets", "${{ matrix.node }}", "${{ matrix.target }}", "${{ matrix.module }}", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]' >> $GITHUB_ENV;
- name: Cache targets
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.targets_key), '-') }}
path: targets
- name: Cache node_modules
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.node_modules_key), '-') }}
path: node_modules
- name: Check if test files changed
id: test_files_changed
uses: tj-actions/changed-files@v44
with:
files: |
spec/**/*
tsconfig.json
tsconfigs/**/*
jest.config.js
jestconfigs/**/*
- name: Check if source files changed
id: source_files_changed
uses: tj-actions/changed-files@v44
with:
files: |
.npmrc
yarn.lock
package.json
tsconfig.json
src/**/*
gulp/**/*
tsconfigs/**/*
integration/**/*
- name: Install dependencies
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' || steps.test_files_changed.outputs.any_modified == 'true' }}
run: |
yarn --ignore-engines --non-interactive
- name: Build package
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }}
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
yarn build ${t:+-t ${t}} ${m:+-m ${m}}
- name: Test package
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' || steps.test_files_changed.outputs.any_modified == 'true' }}
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
yarn test ${t:+-t ${t}} ${m:+-m ${m}} ${{ matrix.args }}
- name: Test importing
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }}
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
set -e;
targetdir="./targets${t:+/${t}}${m:+/${m}}";
pkg_name="$(jq -r '.name' "${targetdir}/package.json")";
pkg_type="$(jq -r '.type' "${targetdir}/package.json")";
# Install the package into a temp dir
_tmp="$(mktemp -d)";
mkdir -p "$(dirname "${_tmp}/node_modules/${pkg_name}")";
cp -ar "${targetdir}" "${_tmp}/node_modules/${pkg_name}";
cd "${_tmp}/node_modules/${pkg_name}";
npm i;
cd "${_tmp}/";
import_paths=(
"${pkg_name}"
"${pkg_name}/Ix"
"${pkg_name}/Ix.iterable"
"${pkg_name}/Ix.iterable.operators"
"${pkg_name}/Ix.asynciterable"
"${pkg_name}/Ix.asynciterable.operators"
"${pkg_name}/iterable/index"
"${pkg_name}/iterable/operators"
"${pkg_name}/iterable/operators/index"
"${pkg_name}/asynciterable/index"
"${pkg_name}/asynciterable/operators"
"${pkg_name}/asynciterable/operators/index"
);
test_import_esm() {
local path;
for path in "${import_paths[@]}"; do
node --input-type=module -e "import '${path}'";
done
}
test_import_cjs() {
local path;
for path in "${import_paths[@]}"; do
node --input-type=commonjs -e "require('${path}')";
done
}
set -x;
if test "${pkg_type}" = "module"; then
# Test importing as ESModule
test_import_esm;
elif test "$m" = umd; then
# Test importing UMD as both CommonJS and ESM
test_import_cjs;
test_import_esm;
else
# Test importing others as both CommonJS and ESM, but allow ESM to fail
test_import_cjs;
test_import_esm || true;
fi
set +x;
cd /;
rm -rf "${_tmp}";