azure-pipelines-tasks-webdeployment-common 4.230.1 → 4.230.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,100 +1,88 @@
1
- import { validate } from './L1JSONVarSubWithComments';
2
- var jsonSubUtil = require('azure-pipelines-tasks-webdeployment-common/jsonvariablesubstitutionutility.js');
1
+ import assert = require('assert');
2
+ import { createEnvTree, substituteJsonVariableV2 } from '../jsonvariablesubstitutionutility';
3
3
 
4
- var envVarObject = jsonSubUtil.createEnvTree([
5
- { name: 'system.debug', value: 'true', secret: false},
6
- { name: 'data.ConnectionString', value: 'database_connection', secret: false},
7
- { name: 'data.userName', value: 'db_admin', secret: false},
8
- { name: 'data.password', value: 'db_pass', secret: true},
9
- { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false},
10
- { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false},
11
- { name: 'user.profile.name.first', value: 'firstName', secret: false},
12
- { name: 'user.profile', value: 'replace_all', secret: false},
13
- { name: 'constructor.name', value: 'newConstructorName', secret: false},
14
- { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false},
15
- { name: 'profile.users', value: '["suaggar","rok","asranja", "chaitanya"]', secret: false},
16
- { name: 'profile.enabled', value: 'false', secret: false},
17
- { name: 'profile.version', value: '1173', secret: false},
18
- { name: 'profile.somefloat', value: '97.75', secret: false},
19
- { name: 'profile.preimum_level', value: '{"suaggar": "V4", "rok": "V5", "asranja": { "type" : "V6"}}', secret: false},
20
- { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false}
21
- ]);
4
+ export function runL1JsonVarSubV2Tests(): void {
5
+ it("Should substitute JSON variables V2", (done: Mocha.Done) => {
6
+ const envVarObject = createEnvTree([
7
+ { name: 'system.debug', value: 'true', secret: false },
8
+ { name: 'data.ConnectionString', value: 'database_connection', secret: false },
9
+ { name: 'data.userName', value: 'db_admin', secret: false },
10
+ { name: 'data.password', value: 'db_pass', secret: true },
11
+ { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false },
12
+ { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false },
13
+ { name: 'user.profile.name.first', value: 'firstName', secret: false },
14
+ { name: 'user.profile', value: 'replace_all', secret: false },
15
+ { name: 'constructor.name', value: 'newConstructorName', secret: false },
16
+ { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false },
17
+ { name: 'profile.users', value: '["suaggar","rok","asranja", "chaitanya"]', secret: false },
18
+ { name: 'profile.enabled', value: 'false', secret: false },
19
+ { name: 'profile.version', value: '1173', secret: false },
20
+ { name: 'profile.somefloat', value: '97.75', secret: false },
21
+ { name: 'profile.preimum_level', value: '{"suaggar": "V4", "rok": "V5", "asranja": { "type" : "V6"}}', secret: false },
22
+ { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false }
23
+ ]);
22
24
 
23
- var jsonObject = {
24
- 'User.Profile': 'do_not_replace',
25
- 'data': {
26
- 'ConnectionString' : 'connect_string',
27
- 'userName': 'name',
28
- 'password': 'pass'
29
- },
30
- '&pl': {
31
- 'ch@r@cter.k^y': 'v@lue'
32
- },
33
- 'system': {
34
- 'debug' : 'no_change'
35
- },
36
- 'user.profile': {
37
- 'name.first' : 'fname'
38
- },
39
- 'constructor.name': 'myconstructorname',
40
- 'constructor': {
41
- 'name': 'myconstructorname',
42
- 'valueOf': 'myconstructorvalue'
43
- },
44
- 'profile': {
45
- 'users': ['arjgupta', 'raagra', 'muthuk'],
46
- 'preimum_level': {
47
- 'arjgupta': 'V1',
48
- 'raagra': 'V2',
49
- 'muthuk': {
50
- 'type': 'V3'
25
+ const jsonObject = {
26
+ 'User.Profile': 'do_not_replace',
27
+ 'data': {
28
+ 'ConnectionString': 'connect_string',
29
+ 'userName': 'name',
30
+ 'password': 'pass'
31
+ },
32
+ '&pl': {
33
+ 'ch@r@cter.k^y': 'v@lue'
34
+ },
35
+ 'system': {
36
+ 'debug': 'no_change'
37
+ },
38
+ 'user.profile': {
39
+ 'name.first': 'fname'
40
+ },
41
+ 'constructor.name': 'myconstructorname',
42
+ 'constructor': {
43
+ 'name': 'myconstructorname',
44
+ 'valueOf': 'myconstructorvalue'
45
+ },
46
+ 'profile': {
47
+ 'users': ['arjgupta', 'raagra', 'muthuk'],
48
+ 'preimum_level': {
49
+ 'arjgupta': 'V1',
50
+ 'raagra': 'V2',
51
+ 'muthuk': {
52
+ 'type': 'V3'
53
+ }
54
+ },
55
+ "enabled": true,
56
+ "version": 2,
57
+ "somefloat": 2.3456
58
+ },
59
+ 'systemsettings': {
60
+ 'appurl': 'https://helloworld.visualstudio.com'
51
61
  }
52
- },
53
- "enabled": true,
54
- "version": 2,
55
- "somefloat": 2.3456
56
- },
57
- 'systemsettings': {
58
- 'appurl': 'https://helloworld.visualstudio.com'
59
- }
60
62
 
61
- }
62
- // Method to be checked for JSON variable substitution
63
- jsonSubUtil.substituteJsonVariableV2(jsonObject, envVarObject);
63
+ };
64
64
 
65
- if(jsonObject['data']['ConnectionString'] === 'database_connection'
66
- && jsonObject['data']['userName'] === 'db_admin'
67
- && jsonObject['systemsettings']['appurl'] == 'https://dev.azure.com/helloworld') {
68
- console.log('JSON - simple string change validated');
69
- }
70
- if(jsonObject['system']['debug'] === 'no_change') {
71
- console.log('JSON - system variable elimination validated');
72
- }
73
- if(jsonObject['&pl']['ch@r@cter.k^y'] === '*.config') {
74
- console.log('JSON - special variables validated');
75
- }
76
- if(jsonObject['User.Profile'] === 'do_not_replace') {
77
- console.log('JSON - case sensitive variables validated');
78
- }
79
- if(jsonObject['constructor.name'] === 'newConstructorName' &&
80
- jsonObject['constructor']['name'] === 'newConstructorName' && jsonObject['constructor']['valueOf'] === 'constructorNewValue') {
81
- console.log('JSON - substitute inbuilt JSON attributes validated');
82
- }
83
- let newArray = ["suaggar", "rok", "asranja", "chaitanya"];
84
- if (jsonObject['profile']['users'].length == 4 && (jsonObject['profile']['users']).every((value, index) => {return value == newArray[index]}) ) {
85
- console.log('JSON - Array Object validated');
86
- }
87
- if(jsonObject['profile']['enabled'] == false) {
88
- console.log('JSON - Boolean validated');
89
- }
90
- if(jsonObject['profile']['somefloat'] == 97.75) {
91
- console.log('JSON - Number(float) validated');
92
- }
93
- if(jsonObject['profile']['version'] == 1173) {
94
- console.log('JSON - Number(int) validated');
95
- }
96
- if(JSON.stringify(jsonObject['profile']['preimum_level']) == JSON.stringify({"suaggar": "V4", "rok": "V5", "asranja": { "type" : "V6"}})) {
97
- console.log('JSON - Object validated');
98
- }
65
+ substituteJsonVariableV2(jsonObject, envVarObject);
66
+
67
+ assert.strictEqual(jsonObject['data']['ConnectionString'], 'database_connection');
68
+ assert.strictEqual(jsonObject['data']['userName'], 'db_admin');
69
+ assert.strictEqual(jsonObject['systemsettings']['appurl'], 'https://dev.azure.com/helloworld');
70
+ assert.strictEqual(jsonObject['system']['debug'], 'no_change');
71
+ assert.strictEqual(jsonObject['&pl']['ch@r@cter.k^y'], '*.config');
72
+ assert.strictEqual(jsonObject['User.Profile'], 'do_not_replace');
73
+ assert.strictEqual(jsonObject['constructor.name'], 'newConstructorName');
74
+ assert.strictEqual(jsonObject['constructor']['name'], 'newConstructorName');
75
+ assert.strictEqual(jsonObject['constructor']['valueOf'], 'constructorNewValue');
76
+ assert.strictEqual(jsonObject['profile']['users'].length, 4);
77
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('suaggar'), -1);
78
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('rok'), -1);
79
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('asranja'), -1);
80
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('chaitanya'), -1);
81
+ assert.strictEqual(jsonObject['profile']['enabled'], false);
82
+ assert.strictEqual(jsonObject['profile']['somefloat'], 97.75);
83
+ assert.strictEqual(jsonObject['profile']['version'], 1173);
84
+ assert.deepStrictEqual(jsonObject['profile']['preimum_level'], { suaggar: "V4", rok: "V5", asranja: { type: "V6" } });
99
85
 
100
- validate();
86
+ done();
87
+ });
88
+ }
@@ -1,5 +1,2 @@
1
- declare var fileEncoding: any;
2
- declare var fileEncodeType: any;
3
- declare var fileEncodeType: any;
4
- declare var fileEncodeType: any;
5
- declare var fileEncodeType: any;
1
+ /// <reference types="mocha" />
2
+ export declare function runL1ValidateFileEncodingTests(this: Mocha.Suite): void;
@@ -1,65 +1,52 @@
1
- var fileEncoding = require('../fileencoding.js');
2
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-8.txt', new Buffer([239, 187, 191, 0]));
3
- if (fileEncodeType[0] === 'utf-8' && fileEncodeType[1]) {
4
- console.log('UTF-8 with BOM validated');
5
- }
6
- try {
7
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32le.txt', new Buffer([255, 254, 0, 0]));
8
- }
9
- catch (exception) {
10
- console.log('UTF-32LE with BOM validated');
11
- }
12
- try {
13
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16be.txt', new Buffer([254, 255, 0, 0]));
14
- }
15
- catch (exception) {
16
- console.log('UTF-16BE with BOM validated');
17
- }
18
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16le.txt', new Buffer([255, 254, 10, 10]));
19
- if (fileEncodeType[0] === 'utf-16le' && fileEncodeType[1]) {
20
- console.log('UTF-16LE with BOM validated');
21
- }
22
- try {
23
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32BE.txt', new Buffer([0, 0, 254, 255]));
24
- }
25
- catch (exception) {
26
- console.log('UTF-32BE with BOM validated');
27
- }
28
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-8.txt', new Buffer([10, 11, 12, 13]));
29
- if (fileEncodeType[0] === 'utf-8' && !fileEncodeType[1]) {
30
- console.log('UTF-8 without BOM validated');
31
- }
32
- try {
33
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32le.txt', new Buffer([255, 0, 0, 0]));
34
- }
35
- catch (exception) {
36
- console.log('UTF-32LE without BOM validated');
37
- }
38
- try {
39
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32be.txt', new Buffer([0, 0, 0, 255]));
40
- }
41
- catch (exception) {
42
- console.log('UTF-32BE without BOM validated');
43
- }
44
- try {
45
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16be.txt', new Buffer([0, 10, 0, 20]));
46
- }
47
- catch (exception) {
48
- console.log('UTF-16BE without BOM validated');
49
- }
50
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16le.txt', new Buffer([20, 0, 10, 0]));
51
- if (fileEncodeType[0] === 'utf-16le' && !fileEncodeType[1]) {
52
- console.log('UTF-16LE without BOM validated');
53
- }
54
- try {
55
- fileEncoding.detectFileEncoding('utfShort.txt', new Buffer([20, 0]));
56
- }
57
- catch (exception) {
58
- console.log('Short File Buffer Error');
59
- }
60
- try {
61
- fileEncoding.detectFileEncoding('utfUnknown.txt', new Buffer([0, 10, 20, 30]));
62
- }
63
- catch (exception) {
64
- console.log('Unknown encoding type');
65
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runL1ValidateFileEncodingTests = void 0;
4
+ const assert = require("assert");
5
+ const fileencoding_1 = require("../fileencoding");
6
+ function runL1ValidateFileEncodingTests() {
7
+ it("UTF-8 with BOM", () => {
8
+ const fileEncodeType = fileencoding_1.detectFileEncoding('utf-8.txt', Buffer.from([239, 187, 191, 0]));
9
+ assert.strictEqual(fileEncodeType[0], 'utf-8');
10
+ assert.strictEqual(fileEncodeType[1], true);
11
+ });
12
+ it("UTF-32LE with BOM", () => {
13
+ assert.throws(() => fileencoding_1.detectFileEncoding('utf-32le.txt', Buffer.from([255, 254, 0, 0])));
14
+ });
15
+ it("UTF-16BE with BOM", () => {
16
+ assert.throws(() => fileencoding_1.detectFileEncoding('utf-16be.txt', Buffer.from([254, 255, 0, 0])));
17
+ });
18
+ it("UTF-16LE with BOM", () => {
19
+ const fileEncodeType = fileencoding_1.detectFileEncoding('utf-16le.txt', Buffer.from([255, 254, 10, 10]));
20
+ assert.strictEqual(fileEncodeType[0], 'utf-16le');
21
+ assert.strictEqual(fileEncodeType[1], true);
22
+ });
23
+ it("UTF-32BE with BOM", () => {
24
+ assert.throws(() => fileencoding_1.detectFileEncoding('utf-32BE.txt', Buffer.from([0, 0, 254, 255])));
25
+ });
26
+ it("UTF-8 without BOM", () => {
27
+ const fileEncodeType = fileencoding_1.detectFileEncoding('utf-8.txt', Buffer.from([10, 11, 12, 13]));
28
+ assert.strictEqual(fileEncodeType[0], 'utf-8');
29
+ assert.strictEqual(fileEncodeType[1], false);
30
+ });
31
+ it("UTF-32LE without BOM", () => {
32
+ assert.throws(() => fileencoding_1.detectFileEncoding('utf-32le.txt', Buffer.from([255, 0, 0, 0])));
33
+ });
34
+ it("UTF-32BE without BOM", () => {
35
+ assert.throws(() => fileencoding_1.detectFileEncoding('utf-32be.txt', Buffer.from([0, 0, 0, 255])));
36
+ });
37
+ it("UTF-16BE without BOM", () => {
38
+ assert.throws(() => fileencoding_1.detectFileEncoding('utf-16be.txt', Buffer.from([0, 10, 0, 20])));
39
+ });
40
+ it("UTF-16LE without BOM", () => {
41
+ const fileEncodeType = fileencoding_1.detectFileEncoding('utf-16le.txt', Buffer.from([20, 0, 10, 0]));
42
+ assert.strictEqual(fileEncodeType[0], 'utf-16le');
43
+ assert.strictEqual(fileEncodeType[1], false);
44
+ });
45
+ it("Short File Buffer Error", () => {
46
+ assert.throws(() => fileencoding_1.detectFileEncoding('utfShort.txt', Buffer.from([20, 0])));
47
+ });
48
+ it("Unknown encoding type", () => {
49
+ assert.throws(() => fileencoding_1.detectFileEncoding('utfUnknown.txt', Buffer.from([0, 10, 20, 30])));
50
+ });
51
+ }
52
+ exports.runL1ValidateFileEncodingTests = runL1ValidateFileEncodingTests;
@@ -1,77 +1,61 @@
1
- var fileEncoding = require('../fileencoding.js');
2
-
3
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-8.txt', new Buffer([239, 187, 191, 0]));
4
- if(fileEncodeType[0] === 'utf-8' && fileEncodeType[1]) {
5
- console.log('UTF-8 with BOM validated');
6
- }
7
-
8
- try {
9
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32le.txt', new Buffer([255, 254, 0, 0]));
10
- }
11
- catch(exception) {
12
- console.log('UTF-32LE with BOM validated');
13
- }
14
-
15
- try {
16
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16be.txt', new Buffer([254, 255, 0 ,0]));
17
- }
18
- catch(exception) {
19
- console.log('UTF-16BE with BOM validated');
20
- }
21
-
22
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16le.txt', new Buffer([255, 254, 10, 10]));
23
- if(fileEncodeType[0] === 'utf-16le' && fileEncodeType[1]) {
24
- console.log('UTF-16LE with BOM validated');
25
- }
26
-
27
- try {
28
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32BE.txt', new Buffer([0, 0, 254, 255]));
29
- }
30
- catch(exception) {
31
- console.log('UTF-32BE with BOM validated');
32
- }
33
-
34
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-8.txt', new Buffer([10, 11, 12, 13]));
35
- if(fileEncodeType[0] === 'utf-8' && !fileEncodeType[1]) {
36
- console.log('UTF-8 without BOM validated');
37
- }
38
-
39
- try {
40
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32le.txt', new Buffer([255, 0, 0, 0]));
41
- }
42
- catch(exception) {
43
- console.log('UTF-32LE without BOM validated');
44
- }
45
-
46
- try {
47
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-32be.txt', new Buffer([0, 0, 0, 255]));
48
- }
49
- catch(exception) {
50
- console.log('UTF-32BE without BOM validated');
51
- }
52
-
53
- try {
54
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16be.txt', new Buffer([0, 10, 0 ,20]));
55
- }
56
- catch(exception) {
57
- console.log('UTF-16BE without BOM validated');
58
- }
59
-
60
- var fileEncodeType = fileEncoding.detectFileEncoding('utf-16le.txt', new Buffer([20, 0, 10, 0]));
61
- if(fileEncodeType[0] === 'utf-16le' && !fileEncodeType[1]) {
62
- console.log('UTF-16LE without BOM validated');
63
- }
64
-
65
- try {
66
- fileEncoding.detectFileEncoding('utfShort.txt', new Buffer([20, 0]));
67
- }
68
- catch(exception) {
69
- console.log('Short File Buffer Error');
70
- }
71
-
72
- try {
73
- fileEncoding.detectFileEncoding('utfUnknown.txt', new Buffer([0, 10, 20, 30]));
74
- }
75
- catch(exception) {
76
- console.log('Unknown encoding type')
77
- }
1
+ import * as assert from 'assert';
2
+ import { detectFileEncoding } from '../fileencoding';
3
+
4
+ export function runL1ValidateFileEncodingTests(this: Mocha.Suite): void {
5
+
6
+ it("UTF-8 with BOM", () => {
7
+ const fileEncodeType = detectFileEncoding('utf-8.txt', Buffer.from([239, 187, 191, 0]));
8
+ assert.strictEqual(fileEncodeType[0], 'utf-8');
9
+ assert.strictEqual(fileEncodeType[1], true);
10
+ });
11
+
12
+ it("UTF-32LE with BOM", () => {
13
+ assert.throws(() => detectFileEncoding('utf-32le.txt', Buffer.from([255, 254, 0, 0])));
14
+ });
15
+
16
+ it("UTF-16BE with BOM", () => {
17
+ assert.throws(() => detectFileEncoding('utf-16be.txt', Buffer.from([254, 255, 0, 0])));
18
+ });
19
+
20
+ it("UTF-16LE with BOM", () => {
21
+ const fileEncodeType = detectFileEncoding('utf-16le.txt', Buffer.from([255, 254, 10, 10]));
22
+ assert.strictEqual(fileEncodeType[0], 'utf-16le');
23
+ assert.strictEqual(fileEncodeType[1], true);
24
+ });
25
+
26
+ it("UTF-32BE with BOM", () => {
27
+ assert.throws(() => detectFileEncoding('utf-32BE.txt', Buffer.from([0, 0, 254, 255])));
28
+ });
29
+
30
+ it("UTF-8 without BOM", () => {
31
+ const fileEncodeType = detectFileEncoding('utf-8.txt', Buffer.from([10, 11, 12, 13]));
32
+ assert.strictEqual(fileEncodeType[0], 'utf-8');
33
+ assert.strictEqual(fileEncodeType[1], false);
34
+ });
35
+
36
+ it("UTF-32LE without BOM", () => {
37
+ assert.throws(() => detectFileEncoding('utf-32le.txt', Buffer.from([255, 0, 0, 0])));
38
+ });
39
+
40
+ it("UTF-32BE without BOM", () => {
41
+ assert.throws(() => detectFileEncoding('utf-32be.txt', Buffer.from([0, 0, 0, 255])));
42
+ });
43
+
44
+ it("UTF-16BE without BOM", () => {
45
+ assert.throws(() => detectFileEncoding('utf-16be.txt', Buffer.from([0, 10, 0 ,20])));
46
+ });
47
+
48
+ it("UTF-16LE without BOM", () => {
49
+ const fileEncodeType = detectFileEncoding('utf-16le.txt', Buffer.from([20, 0, 10, 0]));
50
+ assert.strictEqual(fileEncodeType[0], 'utf-16le');
51
+ assert.strictEqual(fileEncodeType[1], false);
52
+ });
53
+
54
+ it("Short File Buffer Error", () => {
55
+ assert.throws(() => detectFileEncoding('utfShort.txt', Buffer.from([20, 0])));
56
+ });
57
+
58
+ it("Unknown encoding type", () => {
59
+ assert.throws(() => detectFileEncoding('utfUnknown.txt', Buffer.from([0, 10, 20, 30])));
60
+ });
61
+ }
@@ -1,3 +1,2 @@
1
- declare var path: any;
2
- declare var ltx: any;
3
- declare var xdtTransform: any;
1
+ /// <reference types="mocha" />
2
+ export declare function runL1XdtTransformTests(this: Mocha.Suite): void;
@@ -1,6 +1,48 @@
1
- var path = require('path');
2
- var ltx = require('ltx');
3
- var xdtTransform = require('azure-pipelines-tasks-webdeployment-common/xdttransformationutility.js');
4
- process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = path.join(__dirname, 'L1XdtTransform');
5
- xdtTransform.applyXdtTransformation(path.join(__dirname, 'L1XdtTransform', 'Web_test.config'), path.join(__dirname, 'L1XdtTransform', 'Web.Debug.config'));
6
- process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = 'DefaultWorkingDirectory';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runL1XdtTransformTests = void 0;
4
+ const tl = require("azure-pipelines-task-lib");
5
+ const assert = require("assert");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const ltx = require("ltx");
9
+ const xdttransformationutility_1 = require("../xdttransformationutility");
10
+ const fileencoding_1 = require("../fileencoding");
11
+ function runL1XdtTransformTests() {
12
+ this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT) || 20000);
13
+ beforeEach(done => {
14
+ tl.cp(getAbsolutePath('Web.config'), getAbsolutePath('Web_test.config'), '-f', false);
15
+ done();
16
+ });
17
+ afterEach(done => {
18
+ try {
19
+ tl.rmRF(getAbsolutePath('Web_test.config'));
20
+ }
21
+ catch (error) {
22
+ tl.debug(error);
23
+ }
24
+ finally {
25
+ done();
26
+ }
27
+ });
28
+ it('Runs successfully with XML Transformation (L1)', function (done) {
29
+ if (tl.getPlatform() !== tl.Platform.Windows) {
30
+ this.skip();
31
+ }
32
+ xdttransformationutility_1.applyXdtTransformation(getAbsolutePath('Web_test.config'), getAbsolutePath('Web.Debug.config'));
33
+ const resultFile = readXmlFile(getAbsolutePath('Web_test.config'));
34
+ const expectFile = readXmlFile(getAbsolutePath('Web_Expected.config'));
35
+ assert(ltx.equal(resultFile, expectFile), 'Should Transform attributes on Web.config');
36
+ done();
37
+ });
38
+ function getAbsolutePath(file) {
39
+ return path.join(__dirname, 'L1XdtTransform', file);
40
+ }
41
+ function readXmlFile(path) {
42
+ const buffer = fs.readFileSync(path);
43
+ const encoding = fileencoding_1.detectFileEncoding(path, buffer)[0].toString();
44
+ const xml = buffer.toString(encoding).replace(/(?<!\r)[\n]+/gm, "\r\n");
45
+ return ltx.parse(xml);
46
+ }
47
+ }
48
+ exports.runL1XdtTransformTests = runL1XdtTransformTests;
@@ -1,6 +1,57 @@
1
- var path = require('path');
2
- var ltx = require('ltx');
3
- var xdtTransform = require('azure-pipelines-tasks-webdeployment-common/xdttransformationutility.js');
4
- process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = path.join(__dirname, 'L1XdtTransform');
5
- xdtTransform.applyXdtTransformation(path.join(__dirname, 'L1XdtTransform', 'Web_test.config'), path.join(__dirname, 'L1XdtTransform', 'Web.Debug.config'));
6
- process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = 'DefaultWorkingDirectory';
1
+ import * as tl from 'azure-pipelines-task-lib';
2
+ import * as assert from 'assert';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import * as ltx from 'ltx';
6
+
7
+ import { applyXdtTransformation } from "../xdttransformationutility";
8
+ import { detectFileEncoding } from "../fileencoding";
9
+
10
+
11
+ export function runL1XdtTransformTests(this: Mocha.Suite) {
12
+
13
+ this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT) || 20000);
14
+
15
+ beforeEach(done => {
16
+ tl.cp(getAbsolutePath('Web.config'), getAbsolutePath('Web_test.config'), '-f', false);
17
+
18
+ done();
19
+ });
20
+
21
+ afterEach(done => {
22
+ try {
23
+ tl.rmRF(getAbsolutePath('Web_test.config'));
24
+ }
25
+ catch (error) {
26
+ tl.debug(error);
27
+ }
28
+ finally {
29
+ done();
30
+ }
31
+ });
32
+
33
+ it('Runs successfully with XML Transformation (L1)', function(done: Mocha.Done) {
34
+ if (tl.getPlatform() !== tl.Platform.Windows) {
35
+ this.skip();
36
+ }
37
+
38
+ applyXdtTransformation(getAbsolutePath('Web_test.config'), getAbsolutePath('Web.Debug.config'));
39
+
40
+ const resultFile = readXmlFile(getAbsolutePath('Web_test.config'));
41
+ const expectFile = readXmlFile(getAbsolutePath('Web_Expected.config'));
42
+ assert(ltx.equal(resultFile, expectFile), 'Should Transform attributes on Web.config');
43
+ done();
44
+
45
+ });
46
+
47
+ function getAbsolutePath(file: string): string {
48
+ return path.join(__dirname, 'L1XdtTransform', file);
49
+ }
50
+
51
+ function readXmlFile(path: string): ltx.Element {
52
+ const buffer = fs.readFileSync(path);
53
+ const encoding = detectFileEncoding(path, buffer)[0].toString();
54
+ const xml = buffer.toString(encoding).replace( /(?<!\r)[\n]+/gm, "\r\n" );
55
+ return ltx.parse(xml);
56
+ }
57
+ }
@@ -1,3 +1,2 @@
1
- declare var xmlSubstitutionUtility: any;
2
- declare var path: any;
3
- declare function xmlVarSub(): Promise<void>;
1
+ /// <reference types="mocha" />
2
+ export declare function runL1XmlVarSubTests(this: Mocha.Suite): void;