Skip to content

Commit fd50c59

Browse files
test: add stream snapshot test
1 parent c4689ee commit fd50c59

File tree

15 files changed

+137
-1
lines changed

15 files changed

+137
-1
lines changed

src/convert/streams.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const stream2buffer = async (stream: Stream): Promise<Buffer> =>
3636
const buf = Array<any>();
3737
stream.on('data', (chunk) => buf.push(chunk));
3838
stream.on('end', () => resolve(Buffer.concat(buf)));
39-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
4039
stream.on('error', (err) => reject(`error converting stream - ${err}`));
4140
});
4241

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.profile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public with sharing class OneClass {
2+
public OneClass() {
3+
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>59.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public with sharing class OneClass {
2+
public OneClass() {
3+
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>59.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<types>
4+
<members>OneClass</members>
5+
<name>ApexClass</name>
6+
</types>
7+
<types>
8+
<members>Admin</members>
9+
<name>Profile</name>
10+
</types>
11+
<version>60.0</version>
12+
</Package>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<custom>false</custom>
4+
<userLicense>Salesforce</userLicense>
5+
<userPermissions>
6+
<enabled>true</enabled>
7+
<name>AIViewInsightObjects</name>
8+
</userPermissions>
9+
</Profile>

test/snapshot/sampleProjects/forceignore/originalSource/classes/BlueClass.cls

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>59.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

test/snapshot/sampleProjects/forceignore/originalSource/classes/OneClass.cls

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>59.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<custom>false</custom>
4+
<userLicense>Salesforce</userLicense>
5+
<userPermissions>
6+
<enabled>true</enabled>
7+
<name>AIViewInsightObjects</name>
8+
</userPermissions>
9+
</Profile>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "forceignore",
3+
"namespace": "",
4+
"packageDirectories": [
5+
{
6+
"default": true,
7+
"path": "force-app"
8+
}
9+
],
10+
"sfdcLoginUrl": "https://login.salesforce.com",
11+
"sourceApiVersion": "52.0"
12+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import * as fs from 'node:fs';
8+
import * as path from 'node:path';
9+
import { dirsAreIdentical, dirEntsToPaths, fileSnap } from '../../helper/conversions';
10+
import { MetadataConverter } from '../../../../src/convert/metadataConverter';
11+
import { ComponentSetBuilder } from '../../../../src/collections/componentSetBuilder';
12+
13+
// we don't want failing tests outputting over each other
14+
/* eslint-disable no-await-in-loop */
15+
16+
describe('Creating and converting ComponentSets with destructive changes', () => {
17+
const testDir = path.join('test', 'snapshot', 'sampleProjects', 'forceignore');
18+
19+
// The directory containing metadata in source format to be converted
20+
const mdapiDir = path.join(testDir, 'originalMdapi');
21+
22+
// The directory of snapshots containing expected conversion results
23+
const snapshotsDir = path.join(testDir, '__snapshots__');
24+
25+
// The directory where metadata is converted as part of testing
26+
const testOutput = path.join(testDir, 'testOutput');
27+
28+
/** Return only the files involved in the conversion */
29+
const getConvertedFilePaths = async (outputDir: string): Promise<string[]> =>
30+
dirEntsToPaths(
31+
await fs.promises.readdir(outputDir, {
32+
recursive: true,
33+
withFileTypes: true,
34+
})
35+
);
36+
37+
it('ignores source format path', async () => {
38+
const cs = await ComponentSetBuilder.build({
39+
metadata: {
40+
metadataEntries: ['ApexClass:OneClass', 'Profile:Admin'],
41+
directoryPaths: [mdapiDir],
42+
},
43+
projectDir: testDir,
44+
});
45+
46+
const sourceOutput = path.join(testOutput, 'source-format');
47+
48+
await new MetadataConverter().convert(cs, 'source', {
49+
type: 'directory',
50+
outputDirectory: sourceOutput,
51+
genUniqueDir: false,
52+
});
53+
54+
const convertedFiles = await getConvertedFilePaths(sourceOutput);
55+
for (const file of convertedFiles) {
56+
await fileSnap(file, testDir);
57+
}
58+
dirsAreIdentical(path.join(snapshotsDir, 'testOutput', 'pre1'), sourceOutput);
59+
});
60+
61+
after(async () => {
62+
await fs.promises.rm(testOutput, { recursive: true, force: true });
63+
});
64+
});

0 commit comments

Comments
 (0)