diff --git a/.gitignore b/.gitignore index c9bf0601..12e08fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ target/ .settings/ /node_modules /package-lock.json +/DefinitelyTyped diff --git a/src/test/scala/org/scalajs/tools/tsimporter/DefinitelyTypedImportSpec.scala b/src/test/scala/org/scalajs/tools/tsimporter/DefinitelyTypedImportSpec.scala new file mode 100644 index 00000000..dfd1e217 --- /dev/null +++ b/src/test/scala/org/scalajs/tools/tsimporter/DefinitelyTypedImportSpec.scala @@ -0,0 +1,40 @@ +package org.scalajs.tools.tsimporter + +import java.io.File + +import org.scalatest.FunSpec + +class DefinitelyTypedImportSpec extends FunSpec { + + val typesDir = new File("DefinitelyTyped/types") + + describe("DefinitelyTyped") { + it("should be present into the root of the directory") { + assert(typesDir.exists(), "DefinitelyTyped not present. Please clone https://github.com/DefinitelyTyped/DefinitelyTyped") + } + } + + describe("scala-js-ts-importer") { + + case class DTProject(name: String, file: File) + + val dtProjects = Option(typesDir.listFiles()) + .getOrElse(Array.empty) + .filter(_.isDirectory) + .map(dir => DTProject(dir.getName, dir.toPath.resolve("index.d.ts").toFile)) + .filter(_.file.isFile) + + val tempOutputFile = File.createTempFile("scala-js-ts-importer-test-", ".scala") + tempOutputFile.deleteOnExit() + val tempOutputFileName = tempOutputFile.getAbsolutePath + + for (DTProject(name, file) <- dtProjects) it(s"should import '$name'") { + val fileName = file.getCanonicalPath + Main.importTsFile(fileName, tempOutputFileName, "test") match { + case Left(errorMessage) => + fail(s"failed importing $fileName: $errorMessage") + case Right(()) => + } + } + } +} diff --git a/update_definitelyTyped.sh b/update_definitelyTyped.sh new file mode 100755 index 00000000..2dd6e846 --- /dev/null +++ b/update_definitelyTyped.sh @@ -0,0 +1,3 @@ +#!/usr/bin/sh +rm -rf DefinitelyTyped +git clone --depth=1 https://github.com/DefinitelyTyped/DefinitelyTyped