testDts.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. const { TypeScriptVersion } = require('@definitelytyped/typescript-versions');
  20. const {
  21. cleanTypeScriptInstalls,
  22. installAllTypeScriptVersions,
  23. typeScriptPath
  24. } = require('@definitelytyped/utils');
  25. const { runTsCompile } = require('./pre-publish');
  26. const globby = require('globby');
  27. const semver = require('semver');
  28. const MIN_VERSION = '3.5.0';
  29. async function installTs() {
  30. // await cleanTypeScriptInstalls();
  31. await installAllTypeScriptVersions();
  32. }
  33. async function runTests() {
  34. const compilerOptions = {
  35. declaration: false,
  36. importHelpers: false,
  37. sourceMap: false,
  38. pretty: false,
  39. removeComments: false,
  40. allowJs: false,
  41. outDir: __dirname + '/../test/types/tmp',
  42. typeRoots: [__dirname + '/../types/dist'],
  43. rootDir: __dirname + '/../test/types',
  44. // Must pass in most strict cases
  45. strict: true
  46. };
  47. const testsList = await globby(__dirname + '/../test/types/*.ts');
  48. for (let version of TypeScriptVersion.shipped) {
  49. if (semver.lt(version + '.0', MIN_VERSION)) {
  50. continue;
  51. }
  52. console.log(`Testing ts version ${version}`);
  53. const ts = require(typeScriptPath(version));
  54. await runTsCompile(ts, compilerOptions, testsList);
  55. console.log(`Finished test of ts version ${version}`);
  56. }
  57. }
  58. async function main() {
  59. await installTs();
  60. await runTests();
  61. }
  62. module.exports = main;
  63. main();