chore: migrate type tests of each to TSTyche (#14994)

This commit is contained in:
Tom Mrazauskas
2024-05-13 08:51:19 +00:00
committed by GitHub
parent 51ef02ddc2
commit 75412371c3
16 changed files with 295 additions and 570 deletions
-150
View File
@@ -18,14 +18,9 @@ const require = createRequire(import.meta.url);
const rootPackageJson = require('../package.json');
const currentTsdTypescriptVersion =
rootPackageJson.devDependencies['@tsd/typescript'];
const currentTypescriptVersion = rootPackageJson.devDependencies['typescript'];
const tsconfigBasePackage = Object.keys(rootPackageJson.devDependencies).find(
packageName => packageName.startsWith('@tsconfig'),
);
const apiExtractorTypescriptVersion =
require('@microsoft/api-extractor/package.json').dependencies['typescript'];
/* eslint-enable import/order */
const baseTsConfig = JSON.parse(
@@ -87,151 +82,6 @@ function smoketest() {
}
}
function typeTests() {
const cwd = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../');
try {
const {stdout: statusStdout} = execa.sync(
'git',
['status', '--porcelain'],
{cwd},
);
if (statusStdout.length > 0) {
throw new Error(
'Repo is not clean - cannot run type tests with old typescript version',
);
}
execa.sync('yarn', ['add', tsconfigBasePackage], {cwd});
execa.sync(
'yarn',
[
'set',
'resolution',
`@tsd/typescript@npm:${currentTsdTypescriptVersion}`,
tsVersion,
],
{cwd},
);
verifyInstalledTsdTypescript();
execa.sync(
'yarn',
[
'set',
'resolution',
`typescript@npm:${currentTypescriptVersion}`,
tsVersion,
],
{cwd},
);
execa.sync(
'yarn',
[
'set',
'resolution',
`typescript@npm:${apiExtractorTypescriptVersion}`,
tsVersion,
],
{cwd},
);
execa.sync('yarn', ['set', 'resolution', 'typescript@npm:*', tsVersion], {
cwd,
});
verifyInstalledTypescript();
execa.sync('yarn', ['test-ts', '--selectProjects', 'type-tests'], {
cwd,
stdio: 'inherit',
});
} finally {
execa.sync('git', ['checkout', 'package.json', 'yarn.lock'], {cwd});
execa.sync('yarn', ['install'], {cwd});
}
function verifyInstalledTsdTypescript() {
const tsdEntries = listInstalledVersion('@tsd/typescript');
if (tsdEntries.length !== 1) {
throw new Error(
`More than one version of @tsd/typescript found: ${tsdEntries.join(
', ',
)}`,
);
}
const tsdVersion = tsdEntries[0].match(/@npm:(\d+\.\d+)\.\d+/);
if (!tsdVersion) {
throw new Error('Unable to verify installed version of @tsd/typescript');
}
if (tsdVersion[1] !== tsVersion) {
throw new Error(
`Installed TSD version is not ${tsVersion}, is ${tsdVersion[1]}`,
);
}
}
function verifyInstalledTypescript() {
const typescriptEntries = listInstalledVersion('typescript');
if (typescriptEntries.length !== 1) {
throw new Error(
`More than one version of typescript found: ${typescriptEntries.join(
', ',
)}`,
);
}
const tsdVersion = typescriptEntries[0].match(/@npm%3A(\d+\.\d+)\.\d+/);
if (!tsdVersion) {
throw new Error('Unable to verify installed version of typescript');
}
if (tsdVersion[1] !== tsVersion) {
throw new Error(
`Installed TSD version is not ${tsVersion}, is ${tsdVersion[1]}`,
);
}
}
function listInstalledVersion(module) {
const {stdout: tsdWhyOutput} = execa.sync(
'yarn',
['why', module, '--json'],
{cwd},
);
const locators = tsdWhyOutput
.split('\n')
.map(JSON.parse)
.map(entry => {
const entries = Object.entries(entry.children);
if (entries.length !== 1) {
throw new Error(
`More than one entry found in ${JSON.stringify(entry, null, 2)}`,
);
}
return entries[0][1].locator;
});
return [...new Set(locators)];
}
}
console.log(chalk.inverse(` Running smoketest using TypeScript@${tsVersion} `));
smoketest();
console.log(chalk.inverse.green(' Successfully ran smoketest '));
console.log(
chalk.inverse(` Running type tests using TypeScript@${tsVersion} `),
);
typeTests();
console.log(chalk.inverse.green(' Successfully ran type tests '));