Skip to content

Commit 1ae15b2

Browse files
committed
Restrict compatibility to AVA 6
1 parent 41d8c6b commit 1ae15b2

File tree

7 files changed

+80
-319
lines changed

7 files changed

+80
-319
lines changed

index.js

Lines changed: 76 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const changeInterpretations = Object.freeze(Object.assign(Object.create(null), {
7575
}));
7676

7777
export default function typescriptProvider({negotiateProtocol}) {
78-
const protocol = negotiateProtocol(['ava-6', 'ava-3.2'], {version: pkg.version});
78+
const protocol = negotiateProtocol(['ava-6'], {version: pkg.version});
7979
if (protocol === null) {
8080
return;
8181
}
@@ -100,141 +100,110 @@ export default function typescriptProvider({negotiateProtocol}) {
100100
]);
101101
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`);
102102

103-
const watchMode = protocol.identifier === 'ava-3.2'
104-
? {
105-
ignoreChange(filePath) {
106-
if (!testFileExtension.test(filePath)) {
107-
return false;
108-
}
109-
110-
return rewritePaths.some(([from]) => filePath.startsWith(from));
111-
},
112-
113-
resolveTestFile(testfile) { // Used under AVA 3.2 protocol by legacy watcher implementation.
114-
if (!testFileExtension.test(testfile)) {
115-
return testfile;
116-
}
117-
118-
const rewrite = rewritePaths.find(([from]) => testfile.startsWith(from));
119-
if (rewrite === undefined) {
120-
return testfile;
121-
}
122-
123-
const [from, to] = rewrite;
124-
let newExtension = '.js';
125-
if (testfile.endsWith('.cts')) {
126-
newExtension = '.cjs';
127-
} else if (testfile.endsWith('.mts')) {
128-
newExtension = '.mjs';
129-
}
130-
131-
return `${to}${testfile.slice(from.length)}`.replace(testFileExtension, newExtension);
132-
},
133-
}
134-
: {
135-
changeInterpretations,
136-
interpretChange(filePath) {
137-
if (config.compile === false) {
138-
for (const [from] of rewritePaths) {
139-
if (testFileExtension.test(filePath) && filePath.startsWith(from)) {
140-
return changeInterpretations.waitForOutOfBandCompilation;
141-
}
103+
const watchMode = {
104+
changeInterpretations,
105+
interpretChange(filePath) {
106+
if (config.compile === false) {
107+
for (const [from] of rewritePaths) {
108+
if (testFileExtension.test(filePath) && filePath.startsWith(from)) {
109+
return changeInterpretations.waitForOutOfBandCompilation;
142110
}
143111
}
112+
}
144113

145-
if (config.compile === 'tsc') {
146-
for (const [, to] of rewritePaths) {
147-
if (filePath.startsWith(to)) {
148-
return changeInterpretations.ignoreCompiled;
149-
}
114+
if (config.compile === 'tsc') {
115+
for (const [, to] of rewritePaths) {
116+
if (filePath.startsWith(to)) {
117+
return changeInterpretations.ignoreCompiled;
150118
}
151119
}
120+
}
152121

153-
return changeInterpretations.unspecified;
154-
},
155-
156-
resolvePossibleOutOfBandCompilationSources(filePath) {
157-
if (config.compile !== false) {
158-
return null;
159-
}
122+
return changeInterpretations.unspecified;
123+
},
160124

161-
// Only recognize .cjs, .mjs and .js files.
162-
if (!/\.(c|m)?js$/.test(filePath)) {
163-
return null;
164-
}
125+
resolvePossibleOutOfBandCompilationSources(filePath) {
126+
if (config.compile !== false) {
127+
return null;
128+
}
165129

166-
for (const [from, to] of rewritePaths) {
167-
if (!filePath.startsWith(to)) {
168-
continue;
169-
}
130+
// Only recognize .cjs, .mjs and .js files.
131+
if (!/\.(c|m)?js$/.test(filePath)) {
132+
return null;
133+
}
170134

171-
const rewritten = `${from}${filePath.slice(to.length)}`;
172-
const possibleExtensions = [];
135+
for (const [from, to] of rewritePaths) {
136+
if (!filePath.startsWith(to)) {
137+
continue;
138+
}
173139

174-
if (filePath.endsWith('.cjs')) {
175-
if (extensions.includes('cjs')) {
176-
possibleExtensions.push({replace: /\.cjs$/, extension: 'cjs'});
177-
}
140+
const rewritten = `${from}${filePath.slice(to.length)}`;
141+
const possibleExtensions = [];
178142

179-
if (extensions.includes('cts')) {
180-
possibleExtensions.push({replace: /\.cjs$/, extension: 'cts'});
181-
}
143+
if (filePath.endsWith('.cjs')) {
144+
if (extensions.includes('cjs')) {
145+
possibleExtensions.push({replace: /\.cjs$/, extension: 'cjs'});
146+
}
182147

183-
if (possibleExtensions.length === 0) {
184-
return null;
185-
}
148+
if (extensions.includes('cts')) {
149+
possibleExtensions.push({replace: /\.cjs$/, extension: 'cts'});
186150
}
187151

188-
if (filePath.endsWith('.mjs')) {
189-
if (extensions.includes('mjs')) {
190-
possibleExtensions.push({replace: /\.mjs$/, extension: 'mjs'});
191-
}
152+
if (possibleExtensions.length === 0) {
153+
return null;
154+
}
155+
}
192156

193-
if (extensions.includes('mts')) {
194-
possibleExtensions.push({replace: /\.mjs$/, extension: 'mts'});
195-
}
157+
if (filePath.endsWith('.mjs')) {
158+
if (extensions.includes('mjs')) {
159+
possibleExtensions.push({replace: /\.mjs$/, extension: 'mjs'});
160+
}
196161

197-
if (possibleExtensions.length === 0) {
198-
return null;
199-
}
162+
if (extensions.includes('mts')) {
163+
possibleExtensions.push({replace: /\.mjs$/, extension: 'mts'});
200164
}
201165

202-
if (filePath.endsWith('.js')) {
203-
if (extensions.includes('js')) {
204-
possibleExtensions.push({replace: /\.js$/, extension: 'js'});
205-
}
166+
if (possibleExtensions.length === 0) {
167+
return null;
168+
}
169+
}
206170

207-
if (extensions.includes('ts')) {
208-
possibleExtensions.push({replace: /\.js$/, extension: 'ts'});
209-
}
171+
if (filePath.endsWith('.js')) {
172+
if (extensions.includes('js')) {
173+
possibleExtensions.push({replace: /\.js$/, extension: 'js'});
174+
}
210175

211-
if (extensions.includes('tsx')) {
212-
possibleExtensions.push({replace: /\.js$/, extension: 'tsx'});
213-
}
176+
if (extensions.includes('ts')) {
177+
possibleExtensions.push({replace: /\.js$/, extension: 'ts'});
178+
}
214179

215-
if (possibleExtensions.length === 0) {
216-
return null;
217-
}
180+
if (extensions.includes('tsx')) {
181+
possibleExtensions.push({replace: /\.js$/, extension: 'tsx'});
218182
}
219183

220-
const possibleDeletedFiles = [];
221-
for (const {replace, extension} of possibleExtensions) {
222-
const possibleFilePath = rewritten.replace(replace, `.${extension}`);
184+
if (possibleExtensions.length === 0) {
185+
return null;
186+
}
187+
}
223188

224-
// Pick the first file path that exists.
225-
if (fs.existsSync(possibleFilePath)) {
226-
return [possibleFilePath];
227-
}
189+
const possibleDeletedFiles = [];
190+
for (const {replace, extension} of possibleExtensions) {
191+
const possibleFilePath = rewritten.replace(replace, `.${extension}`);
228192

229-
possibleDeletedFiles.push(possibleFilePath);
193+
// Pick the first file path that exists.
194+
if (fs.existsSync(possibleFilePath)) {
195+
return [possibleFilePath];
230196
}
231197

232-
return possibleDeletedFiles;
198+
possibleDeletedFiles.push(possibleFilePath);
233199
}
234200

235-
return null;
236-
},
237-
};
201+
return possibleDeletedFiles;
202+
}
203+
204+
return null;
205+
},
206+
};
238207

239208
return {
240209
...watchMode,

test/compilation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {execaNode} from 'execa';
66
import createProviderMacro from './_with-provider.js';
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url));
9-
const withProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'fixtures'));
10-
const withAltProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'broken-fixtures'));
9+
const withProvider = createProviderMacro('ava-6', '6.0.0', path.join(__dirname, 'fixtures'));
10+
const withAltProvider = createProviderMacro('ava-6', '6.0.0', path.join(__dirname, 'broken-fixtures'));
1111

1212
test.before('deleting compiled files', async t => {
1313
t.log(await deleteAsync('test/fixtures/typescript/compiled'));

test/fixtures/install-and-load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
88

99
const provider = makeProvider({
1010
negotiateProtocol() {
11-
return {identifier: 'ava-3.2', ava: {version: '3.15.0'}, projectDir: __dirname};
11+
return {identifier: 'ava-6', ava: {version: '6.0.0'}, projectDir: __dirname};
1212
},
1313
});
1414

test/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {execaNode} from 'execa';
55
import createProviderMacro from './_with-provider.js';
66

77
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8-
const withProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'fixtures'));
8+
const withProvider = createProviderMacro('ava-6', '6.0.0', path.join(__dirname, 'fixtures'));
99

1010
const setup = async provider => ({
1111
state: await provider.main({

test/protocol-ava-3.2.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy