Skip to content

Commit c106071

Browse files
Refactor out devTools to use an external pacakge (#418)
1 parent 54a0803 commit c106071

File tree

9 files changed

+30
-1637
lines changed

9 files changed

+30
-1637
lines changed

.code-generation/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = {
6161
}
6262
},
6363
unsupportedTxParams: ['fl_waveform', 'fl_animated', 'e_tint', 'u_', 'e_theme', 'l_fetch', 'l_text', 'u_text', 'af_'],
64-
unsupportedCode: ['.stroke(', '.textFit(', 'Animated.edit', '.RoundCorners(', 'getVideoFrame', 'Source.image']
64+
unsupportedCode: ['.stroke(', '.textFit(', 'Animated.edit', '.RoundCorners(', 'getVideoFrame', 'Source.image', '.transcode(']
6565
},
6666
"overwrites": {
6767
qualifiers: {

devTools/sanity/createTestFile.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
/* eslint-disable require-jsdoc */
33

44

5-
import {ITxResult} from "./index";
6-
7-
const fs = require('fs');
8-
5+
import {IFrameworkResponse} from "sdk-sanity-generator/dist/interfaces";
96
const prettier = require('prettier');
107

11-
function createTestFile(txs: ITxResult[]){
8+
function createTestFile(txs: IFrameworkResponse[]){
129
let file = `
1310
// In the future, we'll support HOTER tests without name duplication issues, for now it's commented out
1411
// It's stored here since this is built manually, and it's best to keep the work :)
@@ -153,35 +150,34 @@ import { FontStyle } from "qualifiers/fontStyle";
153150
import {Volume} from "../src/qualifiers/volume";
154151
import {FontAntialias} from "../src/qualifiers/FontAntialias";
155152
import {Animated} from "../src/actions/animated";
156-
const CloudinaryImage = CloudinaryMedia;
157-
const CloudinaryVideo = CloudinaryMedia;
153+
import {CloudinaryImage, CloudinaryVideo, CloudinaryMedia} from "../src"
158154
`;
159155

160156
file += `describe("Testing", () => {\n`;
161157

162158
file += txs.map((txResult) => {
163-
let test = `it("${txResult.txString}", () => {`;
159+
let test = `it("${txResult.transformation}", () => {`;
164160
// If the SDK does not support the transformation, we comment out the test
165161

166162
if (txResult.status === 11) {
167163
test += txResult.status === 11 ? '/* SUCCESS, BUT NO GENERATED CODE - THE SDK DOES NOT SUPPORT THIS TRANSFORMATION' : '';
168164
}
169165

170166
if (txResult.status !== 11) {
171-
test += `const tAsset = ${txResult.parsedCode}`;
167+
test += `const tAsset = ${txResult.code}`;
172168

173-
if (txResult.txString.startsWith('http')) {
169+
if (txResult.transformation.startsWith('http')) {
174170

175171
// For URLS, If not a demo cloud, we do not support the compilation test.
176-
if (!txResult.txString.includes('/demo/')) {
177-
throw `Unsupported URL: ${txResult.txString}`;
172+
if (!txResult.transformation.includes('/demo/')) {
173+
throw `Unsupported URL: ${txResult.transformation}`;
178174
}
179175

180176
test += `tAsset.setCloudConfig({cloudName: 'demo'});`;
181177
test += `tAsset.setURLConfig({analytics:false});`;
182-
test += `expect(tAsset.toURL()).toBe('${txResult.txString}');`;
178+
test += `expect(tAsset.toURL()).toBe('${txResult.transformation}');`;
183179
} else {
184-
test += `const parts = '${txResult.txString}'.replace(/\\//g, ',').split(',');\n\n`;
180+
test += `const parts = '${txResult.transformation}'.replace(/\\//g, ',').split(',');\n\n`;
185181
test += `parts.forEach((part) => { expect(tAsset.toString()).toContain(part)})`;
186182
}
187183
}

devTools/sanity/index.ts

Lines changed: 13 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,19 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
/* eslint-disable require-jsdoc */
3-
const querystring = require('querystring');
4-
const fs = require('fs');
5-
const nodeFetch = require('node-fetch');
6-
const file = fs.readFileSync(`${__dirname}/txList`, 'utf-8');
7-
const createTestFile = require('./createTestFile');
8-
9-
export interface ITxResult {
10-
error: string;
11-
txString: string;
12-
parsedCode: string;
13-
status: number;
14-
}
15-
16-
export interface ITXResults {
17-
success: ITxResult[],
18-
fail: ITxResult[]
19-
}
20-
21-
/*
22-
* Remove duplicates and clean lines starting with #
23-
* @type {string[]}
24-
*/
25-
const transformationStrings = ([...new Set(file.split('\n'))] as string[])
26-
.filter((a) => a[0] !== '#').filter((a) => a);
27-
28-
/*
29-
* Set the SDK Code Snippets Service URL (Change domain/port only
30-
*/
31-
const baseURL = `https://staging-code-snippets.cloudinary.com/v1/generate-code`;
32-
33-
const results:ITXResults = {
34-
success:[],
35-
fail: []
36-
};
37-
38-
console.log(`Attempting to generate code for ${transformationStrings.length} transformations\n`);
39-
40-
41-
let counter = 0;
42-
transformationStrings.forEach(async (txString, i) => {
43-
// Space requests apart
44-
await new Promise((res) => {
45-
setTimeout(() => {
46-
res();
47-
}, 30 * i + 1);
48-
});
49-
50-
console.log('Processing transformation:', i);
513

52-
let url = `https://res.cloudinary.com/demo/image/upload/${txString}/sample`;
53-
if (txString.startsWith('http')) {
54-
url = txString;
55-
}
4+
import {ISanityGeneratorResponse} from "sdk-sanity-generator";
565

57-
const queryArgs = {
58-
frameworks: ['js_2'],
59-
url,
60-
hideActionGroups:0
61-
};
62-
63-
const queryString = querystring.stringify(queryArgs, '&', '=', {
64-
encodeURIComponent(a: string) {
65-
return a;
66-
}
67-
});
68-
69-
const URL = `${baseURL}?${queryString}`;
70-
71-
const res = await nodeFetch(URL).catch((e: Error) => {
72-
console.log(e);
73-
});
74-
75-
const frameworksWithCode = await res.json();
76-
77-
// get JS snippets
78-
const JSSnippet = frameworksWithCode[0];
79-
80-
// Fail, but not by design (11 = Expected unnsupported feature
81-
if (JSSnippet.error && JSSnippet.status !== 11) {
82-
results.fail.push({
83-
txString,
84-
error: JSSnippet.raw_code,
85-
parsedCode: null,
86-
status: JSSnippet.status
87-
});
88-
} else { // Success
89-
results.success.push({
90-
txString,
91-
parsedCode: JSSnippet.raw_code,
92-
error: null,
93-
status: JSSnippet.status
94-
});
95-
}
6+
const fs = require('fs');
7+
const sanityGenerator = require('sdk-sanity-generator').sanityGenerator;
8+
const createTestFile = require('./createTestFile');
969

97-
/*
98-
* Store the result in a file of your choosing
99-
*/
100-
if (counter === transformationStrings.length - 1) {
101-
console.log (`Successful transformations: ${results.success.length}`);
102-
console.log (`Failed transformations: ${results.fail.length}`);
103-
fs.writeFileSync(`${__dirname}/results.json`, JSON.stringify(results));
104-
fs.writeFileSync(`${__dirname}/../../__TESTS__/compilation.test.ts`, createTestFile(results.success));
105-
}
106-
counter++;
10+
sanityGenerator({
11+
framework: 'js_2',
12+
requestSpreading: 70
13+
}).then((res: ISanityGeneratorResponse) => {
14+
console.log(res);
15+
console.log(`Successful transformations: ${res.success.length}`);
16+
console.log(`Failed transformations: ${res.error.length}`);
17+
fs.writeFileSync(`${__dirname}/results.json`, JSON.stringify(res.success));
18+
fs.writeFileSync(`${__dirname}/../../__TESTS__/compilation.test.ts`, createTestFile(res.success));
10719
});
108-
109-

devTools/sanity/package-lock.json

Lines changed: 0 additions & 79 deletions
This file was deleted.

devTools/sanity/package.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

devTools/sanity/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)