Skip to content

Commit

Permalink
[Storage] Rollup for tests in storage (#2297)
Browse files Browse the repository at this point in the history
* Rename test files for consistency

* rollup for node tests

* this is undefined, update paths for rollup

* Import dotenv in index.ts

* Update output path in rollup

* delete mocha report conf - pass args in live test cmd

* restructure package.json similar to other pkgs

* Add mocha.reporter.config to publish node results

* Remove unwanted warnings, code for min version

* Update gulp to zip both min and unmin versions

* Update rollup to generate min and unmin versions

* Add (commented) rollup visualizer

* remove unused import path

* remove unnecessary comment

* Update rollup for tests in storage-file

* Update rollup for tests in storage-queue

* add rollup-plugin-json in devdependency

* Update coverage commands

* Update nycrc for code coverage - storage-blob

* Update .nycrc - code coverage -storage{file,queue}

* Update test:node command - storage-blob

* Add rollup-plugin-json

* Update package.json as per rush

* Increase timeout to 120 seconds for tests

* resolve merge conflicts

* Update JavaScript Bundle file names

* Update test path in karma conf

* undo adding rollup-plugin-json for storage-pkgs

* Update test command as the per updates to master

* remove onwarn handler, update with context="null"
  • Loading branch information
HarshaNalluru committed May 15, 2019
1 parent 0940cd5 commit 58a0881
Show file tree
Hide file tree
Showing 66 changed files with 706 additions and 510 deletions.
6 changes: 3 additions & 3 deletions sdk/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const Azure = require("@azure/storage-blob");
To use the SDK with JS bundle in the browsers, simply add a script tag to your HTML pages pointing to the downloaded JS bundle file(s):

```html
<script src="https://mydomain/azure-storage.blob.min.js"></script>
<script src="https://mydomain/azure-storage.file.min.js"></script>
<script src="https://mydomain/azure-storage.queue.min.js"></script>
<script src="https://mydomain/azure-storage-blob.min.js"></script>
<script src="https://mydomain/azure-storage-file.min.js"></script>
<script src="https://mydomain/azure-storage-queue.min.js"></script>
```

The JS bundled file is compatible with [UMD](https://github.com/umdjs/umd) standard, if no module system found, following global variable(s) will be exported:
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# browser #
browser/azure-storage.blob.js
browser/azure-storage.blob.js.map
browser/azure-storage-blob.js
browser/azure-storage-blob.js.map

# dist-test #
dist-test/
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/storage-blob/.nycrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": [
"src/**/*.ts"
"dist-test/index.node.js"
],
"exclude": [
"**/*.d.ts",
Expand All @@ -21,6 +21,7 @@
"html",
"cobertura"
],
"exclude-after-remap":false,
"sourceMap": true,
"instrument": true,
"all": true
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const Azure = require("@azure/storage-blob");
To use the SDK with JS bundle in the browsers, simply add a script tag to your HTML pages pointing to the downloaded JS bundle file(s):

```html
<script src="https://mydomain/azure-storage.blob.min.js"></script>
<script src="https://mydomain/azure-storage-blob.min.js"></script>
```

The JS bundled file is compatible with [UMD](https://github.com/umdjs/umd) standard, if no module system found, following global variable(s) will be exported:
Expand Down
8 changes: 6 additions & 2 deletions sdk/storage/storage-blob/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ const zip = require("gulp-zip");
const version = require("./package.json").version;
const zipFileName = `azurestoragejs.blob-${version}.zip`;

gulp.task("zip", function(callback) {
gulp.task("zip", function (callback) {
gulp
.src(["browser/azure-storage.blob.js", "browser/azure-storage.blob.min.js", "browser/*.txt"])
.src([
"browser/azure-storage-blob.min.js",
"browser/azure-storage-blob.js",
"browser/*.txt"
])
.pipe(zip(zipFileName))
.pipe(gulp.dest("browser"))
.on("end", callback);
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = function(config) {

// Exclude coverage calculation for following files
remapOptions: {
exclude: /node_modules|tests/g
exclude: /node_modules|test/g
},

junitReporter: {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./dist/index.js",
"module": "./dist-esm/src/index.js",
"browser": {
"./dist/index.js": "./browser/azure-storage.blob.min.js",
"./dist/index.js": "./browser/azure-storage-blob.min.js",
"./dist-esm/src/index.js": "./dist-esm/src/index.browser.js",
"./dist-esm/test/utils/index.js": "./dist-esm/test/utils/index.browser.js",
"./dist-esm/src/BlobDownloadResponse.js": "./dist-esm/src/BlobDownloadResponse.browser.js",
Expand Down Expand Up @@ -78,7 +78,7 @@
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "karma start --single-run",
"integration-test:node": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" nyc mocha --compilers ts-node/register --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace --no-timeouts test/*.test.ts test/node/*.test.ts",
"integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 dist-test/index.node.js",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "echo skipped",
"lint": "echo skipped",
Expand Down
136 changes: 136 additions & 0 deletions sdk/storage/storage-blob/rollup.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import nodeResolve from "rollup-plugin-node-resolve";
import multiEntry from "rollup-plugin-multi-entry";
import cjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";
import { uglify } from "rollup-plugin-uglify";
import sourcemaps from "rollup-plugin-sourcemaps";
import shim from "rollup-plugin-shim";
// import visualizer from "rollup-plugin-visualizer";

const version = require("./package.json").version;
const banner = [
"/*!",
` * Azure Storage SDK for JavaScript - Blob, ${version}`,
" * Copyright (c) Microsoft and contributors. All rights reserved.",
" */"
].join("\n");

const pkg = require("./package.json");
const depNames = Object.keys(pkg.dependencies);
const production = process.env.NODE_ENV === "production";

export function nodeConfig(test = false) {
const externalNodeBuiltins = ["@azure/ms-rest-js", "crypto", "fs", "events", "os", "stream"];
const baseConfig = {
input: "dist-esm/src/index.js",
external: depNames.concat(externalNodeBuiltins),
output: {
file: "dist/index.js",
format: "cjs",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
sourcemaps(),
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (true) since this is for node only.
// Allows rollup's dead code elimination to be more aggressive.
"if (isNode)": "if (true)"
}
}),
nodeResolve({ preferBuiltins: true }),
cjs()
]
};

if (test) {
// entry point is every test file
baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/node/*.spec.js"];
baseConfig.plugins.unshift(multiEntry({ exports: false }));

// different output file
baseConfig.output.file = "dist-test/index.node.js";

// mark assert as external
baseConfig.external.push("assert", "fs", "path");

baseConfig.context = "null";
} else if (production) {
baseConfig.plugins.push(uglify());
}

return baseConfig;
}

export function browserConfig(test = false, production = false) {
const baseConfig = {
input: "dist-esm/src/index.browser.js",
external: ["ms-rest-js"],
output: {
file: "browser/azure-storage-blob.js",
banner: banner,
format: "umd",
name: "azblob",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
sourcemaps(),
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (false) since this is for
// browser only. Rollup's dead code elimination will remove
// any code guarded by if (isNode) { ... }
"if (isNode)": "if (false)"
}
}),
// os is not used by the browser bundle, so just shim it
shim({
dotenv: `export function config() { }`,
os: `
export const type = 1;
export const release = 1;
`
}),
nodeResolve({
mainFields: ["module", "browser"],
preferBuiltins: false
}),
cjs({
namedExports: {
events: ["EventEmitter"],
assert: ["ok", "deepEqual", "equal", "fail", "deepStrictEqual", "notDeepEqual"]
}
})
]
};

if (test) {
baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/browser/*.spec.js"];
baseConfig.plugins.unshift(multiEntry({ exports: false }));
baseConfig.output.file = "dist-test/index.browser.js";
baseConfig.context = "null";
} else if (production) {
baseConfig.output.file = "browser/azure-storage-blob.min.js";
baseConfig.plugins.push(
uglify({
output: {
preamble: banner
}
})
// Comment visualizer because it only works on Node.js 8+; Uncomment it to get bundle analysis report
// visualizer({
// filename: "./statistics.html",
// sourcemap: true
// })
);
}

return baseConfig;
}
103 changes: 13 additions & 90 deletions sdk/storage/storage-blob/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,18 @@
import nodeResolve from "rollup-plugin-node-resolve";
import { uglify } from "rollup-plugin-uglify";
import replace from "rollup-plugin-replace";
import commonjs from "rollup-plugin-commonjs";
import shim from "rollup-plugin-shim";
// import visualizer from "rollup-plugin-visualizer";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const version = require("./package.json").version;
const banner = [
"/*!",
` * Azure Storage SDK for JavaScript - Blob, ${version}`,
" * Copyright (c) Microsoft and contributors. All rights reserved.",
" */"
].join("\n");
import * as base from "./rollup.base.config";

const nodeRollupConfigFactory = () => {
return {
external: ["@azure/ms-rest-js", "crypto", "fs", "events", "os", "stream"],
input: "dist-esm/src/index.js",
output: {
file: "dist/index.js",
format: "cjs",
sourcemap: true
},
preserveSymlinks: false,
plugins: [nodeResolve(), uglify()]
};
};
const inputs = [];

const browserRollupConfigFactory = (isProduction) => {
const browserRollupConfig = {
input: "dist-esm/src/index.browser.js",
output: {
file: "browser/azure-storage.blob.js",
banner: banner,
format: "umd",
name: "azblob",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (false) since this is for
// browser only. Rollup's dead code elimination will remove
// any code guarded by if (isNode) { ... }
"if (isNode)": "if (false)"
}
}),
// os is not used by the browser bundle, so just shim it
shim({
dotenv: `export function config() { }`,
os: `
export const type = 1;
export const release = 1;
`
}),
nodeResolve({
mainFields: ["module", "browser"],
preferBuiltins: false
}),
commonjs({
namedExports: {
events: ["EventEmitter"],
assert: ["ok", "deepEqual", "equal", "fail", "deepStrictEqual", "notDeepEqual"]
}
})
]
};
if (!process.env.ONLY_BROWSER) {
inputs.push(base.nodeConfig());
}

if (isProduction) {
browserRollupConfig.output.file = "browser/azure-storage.blob.min.js";
browserRollupConfig.plugins.push(
uglify({
output: {
preamble: banner
}
})
// Comment visualizer because it only works on Node.js 8+; Uncomment it to get bundle analysis report
// visualizer({
// filename: "./statistics.html",
// sourcemap: true
// })
);
}
// Disable this until we are ready to run rollup for the browser.
if (!process.env.ONLY_NODE) {
inputs.push(base.browserConfig());
inputs.push(base.browserConfig(false, true));
}

return browserRollupConfig;
};

export default [
browserRollupConfigFactory(false),
browserRollupConfigFactory(true),
nodeRollupConfigFactory()
];
export default inputs;
15 changes: 4 additions & 11 deletions sdk/storage/storage-blob/rollup.test.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import multi from "rollup-plugin-multi-entry";
import baseConfig from "./rollup.config";
import sourcemaps from "rollup-plugin-sourcemaps";
const [browser] = baseConfig;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

browser.input = ["dist-esm/test/*.js", "dist-esm/test/browser/*.js"];
browser.output.sourcemap = "inline";
browser.output.file = "dist-test/index.browser.js";
browser.plugins.unshift(multi());
browser.plugins.unshift(sourcemaps());
browser.context = "null";
import * as base from "./rollup.base.config";

export default [browser];
export default [base.nodeConfig(true), base.browserConfig(true)];
12 changes: 4 additions & 8 deletions sdk/storage/storage-blob/test/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SharedKeyCredential } from "../../src/credentials/SharedKeyCredential";
import { ServiceURL } from "../../src/ServiceURL";
import { StorageURL } from "../../src/StorageURL";
import { getUniqueName } from "./testutils.common";
import * as dotenv from "dotenv";
dotenv.config({ path: "../.env" });

export * from "./testutils.common";

Expand All @@ -20,9 +22,7 @@ export function getGenericBSU(accountType: string, accountNameSuffix: string = "
accountKey = process.env[accountKeyEnvVar];

if (!accountName || !accountKey || accountName === "" || accountKey === "") {
throw new Error(
`${accountNameEnvVar} and/or ${accountKeyEnvVar} environment variables not specified.`
);
throw new Error(`${accountNameEnvVar} and/or ${accountKeyEnvVar} environment variables not specified.`);
}

const credentials = new SharedKeyCredential(accountName, accountKey);
Expand Down Expand Up @@ -69,11 +69,7 @@ export async function bodyToString(
});
}

export async function createRandomLocalFile(
folder: string,
blockNumber: number,
blockSize: number
): Promise<string> {
export async function createRandomLocalFile(folder: string, blockNumber: number, blockSize: number): Promise<string> {
return new Promise<string>((resolve, reject) => {
const destFile = path.join(folder, getUniqueName("tempfile."));
const ws = fs.createWriteStream(destFile);
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-file/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# browser #
browser/azure-storage.file.js
browser/azure-storage.file.js.map
browser/azure-storage-file.js
browser/azure-storage-file.js.map

# dist-test #
dist-test/
Expand Down

0 comments on commit 58a0881

Please sign in to comment.