build: add Bazel test for TS indexer (#3810)

diff --git a/kythe/typescript/BUILD b/kythe/typescript/BUILD
index d753837..13e5231 100644
--- a/kythe/typescript/BUILD
+++ b/kythe/typescript/BUILD
@@ -2,6 +2,7 @@
 
 load("@npm_bazel_typescript//:index.bzl", "ts_library", "ts_config")
 load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
+load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
 
 ts_config(
     name = "tsconfig",
@@ -45,6 +46,15 @@
     ],
 )
 
+nodejs_test(
+    name = "indexer_test",
+    data = [":test_ts"] + glob(["testdata/**/*"]) + [
+        "//kythe/go/platform/tools/entrystream",
+        "//kythe/cxx/verifier",
+    ],
+    entry_point = ":test.ts",
+)
+
 jasmine_node_test(
     name = "utf8_test",
     deps = [":utf8_test_ts"],
diff --git a/kythe/typescript/test.ts b/kythe/typescript/test.ts
index 950861e..81e13cf 100644
--- a/kythe/typescript/test.ts
+++ b/kythe/typescript/test.ts
@@ -25,12 +25,20 @@
 
 import * as assert from 'assert';
 import * as child_process from 'child_process';
+import * as fs from 'fs';
 import * as path from 'path';
 import * as ts from 'typescript';
 
 import * as indexer from './indexer';
 
 const KYTHE_PATH = process.env['KYTHE'] || '/opt/kythe';
+const RUNFILES = process.env['RUNFILES_DIR'];
+
+const ENTRYSTREAM = RUNFILES ?
+    path.resolve('kythe/go/platform/tools/entrystream/entrystream') :
+    path.resolve(KYTHE_PATH, 'tools/entrystream');
+const VERIFIER = RUNFILES ? path.resolve('kythe/cxx/verifier/verifier') :
+                            path.resolve(KYTHE_PATH, 'tools/verifier');
 
 /**
  * createTestCompilerHost creates a ts.CompilerHost that caches its default
@@ -72,9 +80,7 @@
   const program = ts.createProgram([test], options, host);
 
   const verifier = child_process.spawn(
-      `${KYTHE_PATH}/tools/entrystream --read_format=json |` +
-          `${KYTHE_PATH}/tools/verifier ${test}`,
-      [], {
+      `${ENTRYSTREAM} --read_format=json | ${VERIFIER} ${test}`, [], {
         stdio: ['pipe', process.stdout, process.stderr],
         shell: true,
       });
@@ -157,6 +163,9 @@
 }
 
 async function testMain(args: string[]) {
+  if (RUNFILES) {
+    process.chdir('kythe/typescript');
+  }
   testLoadTsConfig();
   await testIndexer(args);
   await testPlugin();