Skip to content

Commit

Permalink
Add dockerfile based tests for azure-sdk-for-js and `office-ui-fabr…
Browse files Browse the repository at this point in the history
…ic-react` (#31948)

* Add dockerfile based tests

* Update tests/cases/docker/README.md

Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Combine sanitize functions

* Add some debugging instructions to README

* Fix listed command order
  • Loading branch information
weswigham committed Jun 20, 2019
1 parent 36df28d commit c39a877
Show file tree
Hide file tree
Showing 11 changed files with 706 additions and 1 deletion.
48 changes: 48 additions & 0 deletions .dockerignore
@@ -0,0 +1,48 @@
node_modules
.node_modules
built/*
test-args.txt
~*.docx
\#*\#
.\#*
src/harness/*.js
src/compiler/diagnosticInformationMap.generated.ts
src/compiler/diagnosticMessages.generated.json
src/parser/diagnosticInformationMap.generated.ts
src/parser/diagnosticMessages.generated.json
rwc-report.html
*.swp
build.json
*.actual
*.config
scripts/debug.bat
scripts/run.bat
scripts/word2md.js
scripts/buildProtocol.js
scripts/ior.js
scripts/authors.js
scripts/configurePrerelease.js
scripts/open-user-pr.js
scripts/open-cherry-pick-pr.js
scripts/processDiagnosticMessages.d.ts
scripts/processDiagnosticMessages.js
scripts/produceLKG.js
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
scripts/generateLocalizedDiagnosticMessages.js
scripts/*.js.map
scripts/typings/
coverage/
internal/
**/.DS_Store
.settings
**/.vs
.idea
yarn.lock
yarn-error.log
.parallelperf.*
.failed-tests
TEST-results.xml
package-lock.json
tests
.vscode
.git
2 changes: 2 additions & 0 deletions .npmignore
Expand Up @@ -29,3 +29,5 @@ package-lock.json
yarn.lock
CONTRIBUTING.md
TEST-results.xml
.dockerignore
Dockerfile
7 changes: 7 additions & 0 deletions Dockerfile
@@ -0,0 +1,7 @@
# We use this dockerfile to build a packed tarfile which we import in our `docker` tests
FROM node:current
COPY . /typescript
WORKDIR /typescript
RUN npm install
RUN npm i -g gulp-cli
RUN gulp configure-insiders && gulp LKG && gulp clean && npm pack .
2 changes: 1 addition & 1 deletion src/harness/runnerbase.ts
@@ -1,4 +1,4 @@
type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user" | "dt";
type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user" | "dt" | "docker";
type CompilerTestKind = "conformance" | "compiler";
type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server";

Expand Down
71 changes: 71 additions & 0 deletions src/testRunner/externalCompileRunner.ts
Expand Up @@ -106,6 +106,77 @@ ${stripAbsoluteImportPaths(result.stderr.toString().replace(/\r\n/g, "\n"))}`;
}
}

class DockerfileRunner extends ExternalCompileRunnerBase {
readonly testDir = "tests/cases/docker/";
kind(): TestRunnerKind {
return "docker";
}
initializeTests(): void {
// Read in and evaluate the test list
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();

// tslint:disable-next-line:no-this-assignment
const cls = this;
describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) {
this.timeout(cls.timeout); // 20 minutes
before(() => {
cls.exec("docker", ["build", ".", "-t", "typescript/typescript"], { cwd: Harness.IO.getWorkspaceRoot() }); // cached because workspace is hashed to determine cacheability
});
for (const test of testList) {
const directory = typeof test === "string" ? test : test.file;
const cwd = path.join(Harness.IO.getWorkspaceRoot(), cls.testDir, directory);
it(`should build ${directory} successfully`, () => {
const imageName = `tstest/${directory}`;
cls.exec("docker", ["build", "--no-cache", ".", "-t", imageName], { cwd }); // --no-cache so the latest version of the repos referenced is always fetched
const cp: typeof import("child_process") = require("child_process");
Harness.Baseline.runBaseline(`${cls.kind()}/${directory}.log`, cls.report(cp.spawnSync(`docker`, ["run", imageName], { cwd, timeout: cls.timeout, shell: true })));
});
}
});
}

private timeout = 1_200_000; // 20 minutes;
private exec(command: string, args: string[], options: { cwd: string, timeout?: number }): void {
const cp: typeof import("child_process") = require("child_process");
const stdio = isWorker ? "pipe" : "inherit";
const res = cp.spawnSync(command, args, { timeout: this.timeout, shell: true, stdio, ...options });
if (res.status !== 0) {
throw new Error(`${command} ${args.join(" ")} for ${options.cwd} failed: ${res.stderr && res.stderr.toString()}`);
}
}
report(result: ExecResult) {
// tslint:disable-next-line:no-null-keyword
return result.status === 0 && !result.stdout.length && !result.stderr.length ? null : `Exit Code: ${result.status}
Standard output:
${sanitizeDockerfileOutput(result.stdout.toString())}
Standard error:
${sanitizeDockerfileOutput(result.stderr.toString())}`;
}
}

function sanitizeDockerfileOutput(result: string): string {
return stripAbsoluteImportPaths(sanitizeTimestamps(stripANSIEscapes(normalizeNewlines(result))));
}

function normalizeNewlines(result: string): string {
return result.replace(/\r\n/g, "\n");
}

function stripANSIEscapes(result: string): string {
return result.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, "");
}

function sanitizeTimestamps(result: string): string {
return result.replace(/\[\d?\d:\d\d:\d\d (A|P)M\]/g, "[XX:XX:XX XM]")
.replace(/\d+(\.\d+)? seconds?/g, "? seconds")
.replace(/\d+(\.\d+)? minutes?/g, "")
.replace(/\d+(\.\d+)?s/g, "?s")
.replace(/\d+.\d+.\d+-insiders.\d\d\d\d\d\d\d\d/g, "X.X.X-insiders.xxxxxxxx");
}


/**
* Import types and some other error messages use absolute paths in errors as they have no context to be written relative to;
* This is problematic for error baselines, so we grep for them and strip them out.
Expand Down
6 changes: 6 additions & 0 deletions src/testRunner/runner.ts
Expand Up @@ -40,6 +40,8 @@ function createRunner(kind: TestRunnerKind): RunnerBase {
return new UserCodeRunner();
case "dt":
return new DefinitelyTypedRunner();
case "docker":
return new DockerfileRunner();
}
return ts.Debug.fail(`Unknown runner kind ${kind}`);
}
Expand Down Expand Up @@ -172,6 +174,9 @@ function handleTestConfig() {
case "dt":
runners.push(new DefinitelyTypedRunner());
break;
case "docker":
runners.push(new DockerfileRunner());
break;
}
}
}
Expand All @@ -194,6 +199,7 @@ function handleTestConfig() {
// CRON-only tests
if (process.env.TRAVIS_EVENT_TYPE === "cron") {
runners.push(new UserCodeRunner());
runners.push(new DockerfileRunner());
}
}
if (runUnitTests === undefined) {
Expand Down
95 changes: 95 additions & 0 deletions tests/baselines/reference/docker/azure-sdk.log
@@ -0,0 +1,95 @@
Exit Code: 1
Standard output:


Rush Multi-Project Build Tool 5.7.3 - https://rushjs.io


Starting "rush rebuild"

Executing a maximum of 1 simultaneous processes...

[@azure/abort-controller] started
1 of 18: [@azure/abort-controller] completed successfully in ? seconds
[@azure/cosmos] started
2 of 18: [@azure/cosmos] completed successfully in ? seconds
[@azure/event-hubs] started
3 of 18: [@azure/event-hubs] completed successfully in ? seconds
[@azure/service-bus] started
Warning: You have changed the public API signature for this project. Updating review/service-bus.api.md
[@azure/storage-blob] started
5 of 18: [@azure/storage-blob] completed successfully in ? seconds
[@azure/storage-datalake] started
6 of 18: [@azure/storage-datalake] completed successfully in ? seconds
[@azure/storage-file] started
7 of 18: [@azure/storage-file] completed successfully in ? seconds
[@azure/storage-queue] started
8 of 18: [@azure/storage-queue] completed successfully in ? seconds
[@azure/template] started
9 of 18: [@azure/template] completed successfully in ? seconds
[@azure/core-http] started
10 of 18: [@azure/core-http] completed successfully in ? seconds
[@azure/core-paging] started
11 of 18: [@azure/core-paging] completed successfully in ? seconds
[@azure/event-processor-host] started
12 of 18: [@azure/event-processor-host] completed successfully in ? seconds
[testhub] started
13 of 18: [testhub] completed successfully in ? seconds
[@azure/identity] started
14 of 18: [@azure/identity] completed successfully in ? seconds
[@azure/core-amqp] started
[@azure/keyvault-certificates] started
15 of 18: [@azure/keyvault-certificates] completed successfully in ? seconds
[@azure/keyvault-keys] started
16 of 18: [@azure/keyvault-keys] completed successfully in ? seconds
[@azure/keyvault-secrets] started
17 of 18: [@azure/keyvault-secrets] completed successfully in ? seconds

SUCCESS (16)
================================
@azure/abort-controller (? seconds)
@azure/core-http (? seconds)
@azure/core-paging (? seconds)
@azure/cosmos (? seconds)
@azure/event-hubs (? seconds)
@azure/event-processor-host (? seconds)
@azure/identity (? seconds)
@azure/keyvault-certificates (? seconds)
@azure/keyvault-keys (? seconds)
@azure/keyvault-secrets (? seconds)
@azure/storage-blob (? seconds)
@azure/storage-datalake (? seconds)
@azure/storage-file (? seconds)
@azure/storage-queue (? seconds)
@azure/template (? seconds)
testhub (? seconds)
================================

SUCCESS WITH WARNINGS (1)
================================
@azure/service-bus (? seconds)
Warning: You have changed the public API signature for this project. Updating review/service-bus.api.md
================================

FAILURE (1)
================================
@azure/core-amqp (? seconds)
>>> @azure/core-amqp
tsc -p . && rollup -c 2>&1
src/errors.ts(579,20): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'typeof ConditionErrorNameMapper'.
src/errors.ts(600,34): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'typeof SystemErrorConditionMapper'.
src/errors.ts(601,20): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'typeof ConditionErrorNameMapper'.
================================


Error: Project(s) failed to build
rush rebuild - Errors! ( ? seconds)



Standard error:
Your version of Node.js (12.4.0) has not been tested with this release of Rush. The Rush team will not accept issue reports for it. Please consider upgrading Rush or downgrading Node.js.
4 of 18: [@azure/service-bus] completed with warnings in ? seconds

14 of 18: [@azure/core-amqp] failed to build!
[@azure/core-amqp] Returned error code: 2

0 comments on commit c39a877

Please sign in to comment.