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

Backport findSourceMap() workaround to AVA 4 #3094

Merged
merged 7 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Upgrade npm
run: npm install --global npm@^8.12
run: npm install --global npm@^8.18
- run: npm install --no-audit
- run: npm run cover
- uses: codecov/codecov-action@v2
Expand All @@ -50,7 +50,7 @@ jobs:
node-version: ^18
cache: npm
- name: Upgrade npm
run: npm install --global npm@^8.12
run: npm install --global npm@^8.18
- run: npm install --no-audit
- run: npm i typescript@${TS_VERSION}
env:
Expand All @@ -69,7 +69,7 @@ jobs:
node-version: ^18
cache: npm
- name: Upgrade npm
run: if [[ "$(npm -v)" != "8.12.0" ]]; then npm install --global npm@8.12.0; fi
run: if [[ "$(npm -v)" != "8.18.0" ]]; then npm install --global npm@8.18.0; fi
- run: npm install --no-audit
- name: Test package-lock for unexpected modifications
run: |
Expand All @@ -90,7 +90,7 @@ jobs:
with:
node-version: ^18
- name: Upgrade npm
run: npm install --global npm@^8.12
run: npm install --global npm@^8.18
- run: npm install --no-package-lock --no-audit
- run: npm run cover

Expand All @@ -104,6 +104,6 @@ jobs:
node-version: ^18
cache: npm
- name: Upgrade npm
run: npm install --global npm@^8.12
run: npm install --global npm@^8.18
- run: npm install --no-audit
- run: npx xo
1 change: 1 addition & 0 deletions .xo-config.cjs
Expand Up @@ -36,6 +36,7 @@ module.exports = {
{
files: 'examples/**',
rules: {
'ava/no-ignored-test-files': 'off',
'ava/no-only-test': 'off',
'unicorn/prefer-module': 'off',
},
Expand Down
4 changes: 3 additions & 1 deletion lib/snapshot-manager.js
Expand Up @@ -391,7 +391,9 @@ class Manager {

const resolveSourceFile = mem(file => {
const sourceMap = findSourceMap(file);
if (sourceMap === undefined) {
// Prior to Node.js 18.8.0, the value when a source map could not be found was `undefined`.
// This changed to `null` in <https://github.com/nodejs/node/pull/43875>. Check both.
if (sourceMap === undefined || sourceMap === null) {
return file;
}

Expand Down
12 changes: 9 additions & 3 deletions lib/worker/line-numbers.js
Expand Up @@ -61,7 +61,7 @@ function findTest(locations, declaration) {
const range = (start, end) => Array.from({length: end - start + 1}).fill(start).map((element, index) => element + index);

const translate = (sourceMap, pos) => {
if (sourceMap === undefined) {
if (sourceMap === null) {
return pos;
}

Expand All @@ -88,7 +88,7 @@ export default function lineNumberSelection({file, lineNumbers = []}) {

let locations = parse(file);
let lookedForSourceMap = false;
let sourceMap;
let sourceMap = null;

return () => {
if (!lookedForSourceMap) {
Expand All @@ -98,7 +98,13 @@ export default function lineNumberSelection({file, lineNumbers = []}) {
// Source maps are not available before then.
sourceMap = findSourceMap(file);

if (sourceMap !== undefined) {
if (sourceMap === undefined) {
// Prior to Node.js 18.8.0, the value when a source map could not be found was `undefined`.
// This changed to `null` in <https://github.com/nodejs/node/pull/43875>.
sourceMap = null;
}

if (sourceMap !== null) {
locations = locations.map(({start, end}) => ({
start: translate(sourceMap, start),
end: translate(sourceMap, end),
Expand Down