Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update url-gen version in packages and align tests #215

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@angular/cli": "~12.2.16",
"@angular/compiler-cli": "~12.2.16",
"@cloudinary/html": "^1.11.2",
"@cloudinary/url-gen": "^1.8.7",
"@cloudinary/url-gen": "^1.10.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/projects/cloudinary-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"devDependencies": {
"@angular/common": "~12.2.16",
"@angular/core": "~12.2.16",
"@cloudinary/url-gen": "^1.8.7"
"@cloudinary/url-gen": "^1.10.1"
},
"dependencies": {
"@cloudinary/html": "^1.11.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ describe('analytics', () => {
const imgElement: HTMLImageElement = fixture.nativeElement;
const img = imgElement.querySelector('img');

expect(img.src).toBe('https://res.cloudinary.com/demo/image/upload/sample?_a=AKAABDS0');
expect(img.src).toBe('https://res.cloudinary.com/demo/image/upload/sample?_a=BAKAABDS0');
}));
});
12 changes: 6 additions & 6 deletions packages/html/__tests__/HtmlImageLayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('HtmlImageLayer tests', function () {
const img = document.createElement('img');
new HtmlImageLayer(img, cldImage, [], sdkAnalyticsTokens);
await flushPromises();
expect(img.src).toEqualAnalyticsToken('AXAABAB0');
expect(img.src).toEqualAnalyticsToken('BAXAABAB0');
});

it('should use feature flag for responsive plugin', async function () {
Expand All @@ -36,21 +36,21 @@ describe('HtmlImageLayer tests', function () {
parentElement.append(img);
new HtmlImageLayer(img, cldImage, [responsive({steps: [100]})], sdkAnalyticsTokens);
await flushPromises();
expect(img.src).toEqualAnalyticsToken('AXAABABA');
expect(img.src).toEqualAnalyticsToken('BAXAABABA');
});

it('should use feature flag for placeholder plugin', async function () {
const img = document.createElement('img');
new HtmlImageLayer(img, cldImage, [placeholder()], sdkAnalyticsTokens);
await flushPromises();
expect(img.src).toEqualAnalyticsToken('AXAABABB');
expect(img.src).toEqualAnalyticsToken('BAXAABABB');
});

it('should use feature flag for accessibility plugin', async function () {
const img = document.createElement('img');
new HtmlImageLayer(img, cldImage, [accessibility()], sdkAnalyticsTokens);
await flushPromises();
expect(img.src).toEqualAnalyticsToken('AXAABABD');
expect(img.src).toEqualAnalyticsToken('BAXAABABD');
});

it('should set image src twice if HtmlImageLayer instance won\'t be unmounted', async function () {
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('HtmlImageLayer tests', function () {
expect(imgSrcSpy).toHaveBeenCalledTimes(1);
// test that the initial src is set to a token contains last character "B" which is the character of placeholder plugin
const imgSrcSpyAnalyticsToken = imgSrcSpy.mock.calls[0][0];
expect(imgSrcSpyAnalyticsToken).toEqualAnalyticsToken('AXAABABB');
expect(imgSrcSpyAnalyticsToken).toEqualAnalyticsToken('BAXAABABB');
// trigger load event in order to resolve the 1st promise of the placeholder plugin
img.dispatchEvent(new Event('load'));
await flushPromises();
Expand All @@ -125,6 +125,6 @@ describe('HtmlImageLayer tests', function () {
await flushPromises();
expect(imgSetAttributeSpy).toHaveBeenCalledTimes(1);
// test that the src which set by HtmlImageLayer contains last character "B" which is the character of placeholder plugin
expect(imgSetAttributeSpy.mock.calls[0][1]).toEqualAnalyticsToken('AXAABABB');
expect(imgSetAttributeSpy.mock.calls[0][1]).toEqualAnalyticsToken('BAXAABABB');
});
});
2 changes: 1 addition & 1 deletion packages/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@babel/preset-env": "^7.14.7",
"@babel/preset-typescript": "^7.14.5",
"@cloudinary/url-gen": "^1.8.7",
"@cloudinary/url-gen": "^1.10.1",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@types/jest": "^29.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/html/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type BaseAnalyticsOptions = {sdkSemver: string, techVersion: string, sdkC

export type AnalyticsOptions = Parameters<CloudinaryImage['toURL']>[0];

type FeatureNames = Omit<ITrackedPropertiesThroughAnalytics, 'sdkCode' | 'sdkSemver' | 'techVersion'>
type FeatureNames = Omit<ITrackedPropertiesThroughAnalytics, 'sdkCode' | 'sdkSemver' | 'techVersion' | 'product'>

export type Features = Partial<Record<keyof FeatureNames, boolean>>

Expand Down
2 changes: 1 addition & 1 deletion packages/react/__tests__/analytics-ssr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('ssr analytics', () => {
)
setTimeout(() => {
expect(ElementImageHtml).toContain(
'https://res.cloudinary.com/demo/image/upload/sample?_a=AJAABDS0'
'https://res.cloudinary.com/demo/image/upload/sample?_a=BAJAABDS0'
)
done()
}, 0) // one tick
Expand Down
2 changes: 1 addition & 1 deletion packages/react/__tests__/analytics.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('analytics', () => {
it('creates an img with analytics', function (done) {
const component = mount(<AdvancedImage cldImg={cloudinaryImage} />);
setTimeout(() => {
expect(component.html()).toEqual('<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=AJAABDS0">');
expect(component.html()).toEqual('<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=BAJAABDS0">');
done();
}, 0);// one tick
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@babel/preset-env": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@cloudinary/html": "^1.0.1",
"@cloudinary/url-gen": "^1.8.7",
"@cloudinary/url-gen": "^1.10.1",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"test": "npm run test:dist && npm run test:src",
"test:src": "vue-cli-service test:unit --coverage",
"pretest:src": "replace-in-files --string='../../dist' --replacement='../../src' tests/unit/*.spec.ts",
"test:dist": "npm run build && VUE_TEST_ENV_TEST_ENV=DIST vue-cli-service test:unit",
"test:dist": "npm run build && VUE_TEST_ENV=DIST vue-cli-service test:unit",
"pretest:dist": "replace-in-files --string='../../src\"' --replacement='../../dist\"' tests/unit/*.spec.ts",
"serve:coverage": "http-server coverage/lcov-report",
"lint": "vue-cli-service lint"
},
"devDependencies": {
"@cloudinary/html": "^1.0.1",
"@cloudinary/url-gen": "^1.8.7",
"@cloudinary/url-gen": "^1.10.1",
"@rollup/plugin-replace": "^4.0.0",
"@sinonjs/fake-timers": "^9.1.2",
"@types/jest": "^27.0.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/vue/tests/unit/analytics-ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const cloudinaryImage = new CloudinaryImage("sample", { cloudName: "demo" });

describe("analytics", () => {
testIf(
!(process.env.VUE3_TEST_ENV === "DIST"),
!(process.env.VUE_TEST_ENV === "DIST"),
"creates an img with analytics using src",
async () => {
// Update src analytics value
Expand All @@ -28,13 +28,13 @@ describe("analytics", () => {
});
const html = await renderToString(app);
expect(html).toMatch(
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=AL'
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=BALAABDS0'
);
}
);

testIf(
process.env.VUE3_TEST_ENV === "DIST",
process.env.VUE_TEST_ENV === "DIST",
"creates an img with analytics using dist",
async () => {
const app = createSSRApp({
Expand All @@ -46,7 +46,7 @@ describe("analytics", () => {
});
const html = await renderToString(app);
expect(html).toMatch(
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=AL'
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=BALFJtDL0'
);
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/tests/unit/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("analytics", () => {
await waitTicks(1);

expect(component.html()).toMatch(
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=AL'
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=BALAABDS0'
);
}
);
Expand All @@ -36,7 +36,7 @@ describe("analytics", () => {
await waitTicks(1);

expect(component.html()).toMatch(
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=AL'
'<img src="https://res.cloudinary.com/demo/image/upload/sample?_a=BALFJtDL0'
);
}
);
Expand Down
6 changes: 6 additions & 0 deletions packages/vue/tests/unit/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { nextTick } from "vue";
import { SDKAnalyticsConstants } from "../../src/internal/SDKAnalyticsConstants";

/**
* Wait number of ticks
Expand All @@ -20,3 +21,8 @@ export const waitTicks = async (ticks: number) => {
*/
export const testIf = (condition: boolean, ...args: [string, () => void]) =>
condition ? test(...args) : {};

export const setAnalyticsConstants = () => {
SDKAnalyticsConstants.sdkSemver = "1.0.0";
SDKAnalyticsConstants.techVersion = "10.2.5";
};