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

IK-1482 #1

Merged
merged 84 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
35f8424
IKImage
Jun 4, 2024
e78a8c2
IKImage
Jun 4, 2024
8eddaaa
IKUpload
Jun 5, 2024
c0b3eac
rollup and IKVideo
Jun 6, 2024
59a2ec7
demo app
Jun 10, 2024
2ce0ef7
ci
Jun 10, 2024
6c9cc01
ci
Jun 10, 2024
46c6085
remove logs
Jun 10, 2024
58f836a
updated package.json
Jun 10, 2024
9f269bc
readme.md
Jun 10, 2024
ca72c26
updated variables
Jun 10, 2024
3100299
fixed types
Jun 10, 2024
f65b529
updated type
Jun 10, 2024
d535a08
updated readme.md
Jun 11, 2024
59c14e0
updated readme.md
Jun 11, 2024
9e8ccd7
updated readme.md
Jun 11, 2024
8e42bce
updated readme.md
Jun 11, 2024
3bb2a82
updated readme.md
Jun 11, 2024
d225f1e
updated readme
Jun 11, 2024
2721920
updated readme
Jun 11, 2024
517af6e
updated readme
Jun 11, 2024
6993679
fixed type issue in IkUpload onError
Jun 12, 2024
30560f4
fix url
Jun 13, 2024
0fdff5d
fix url
Jun 13, 2024
289dc7d
fix test cases
Jun 13, 2024
e8abd8d
updated readme
Jun 13, 2024
ee1d518
fix
Jun 13, 2024
c768865
fix
Jun 13, 2024
0328e69
fix type issue
Jun 17, 2024
eb36d24
updated required parameter in readme
Jun 18, 2024
d86d704
updated link in readme
Jun 18, 2024
0c777b3
added ImageKitProvider and ImageKitContext
Jul 3, 2024
b865be0
added imageKitContext usage example in readme
Jul 3, 2024
5d21d7b
updated readme
Jul 3, 2024
da874ee
addressed feedbacks
Jul 4, 2024
cd10141
addressed feedbacks
Jul 5, 2024
8e03d8b
updated example
Jul 5, 2024
5868e89
updated example
Jul 5, 2024
5586d68
updated example
Jul 5, 2024
9a193bd
updated ci
Jul 5, 2024
f6c2d34
updated ci
Jul 5, 2024
f7c9f83
resolve liniting issue
Jul 5, 2024
ccd6ee4
updated ci
Jul 5, 2024
0d0321d
updated ci
Jul 5, 2024
aa59043
added page-ruter example
Jul 5, 2024
a7263a4
updated readme
Jul 5, 2024
f665db2
updated the logic
Jul 8, 2024
c420755
updated the logic
Jul 8, 2024
8ad7a6a
updated the logic
Jul 8, 2024
4298a98
updated the logic
Jul 8, 2024
1a6990f
updated the logic
Jul 8, 2024
c566d32
updated the logic
Jul 8, 2024
ef66eb8
updated the logic
Jul 8, 2024
e5c5f4d
updated the logic
Jul 8, 2024
56ab509
updated the logic
Jul 8, 2024
1a93be6
updated the logic
Jul 8, 2024
59d5338
updated the logic
Jul 8, 2024
f98d135
updated the logic
Jul 8, 2024
c4ad25b
updated the logic
Jul 8, 2024
9d05f41
updated the logic
Jul 8, 2024
4fa7f2a
updated the logic
Jul 8, 2024
4f91922
updated the logic
Jul 8, 2024
60fcd9d
updated the logic
Jul 9, 2024
fdd280f
updated the logic
Jul 9, 2024
ae2d97c
updated the logic
Jul 9, 2024
0227695
updated the logic
Jul 9, 2024
6ff734a
updated the logic
Jul 9, 2024
a765485
updated the logic
Jul 9, 2024
7928266
updated the logic
Jul 9, 2024
2d65ef6
updated the logic
Jul 9, 2024
30a9ea2
updated the logic
Jul 9, 2024
7a122c4
updated the logic
Jul 9, 2024
8929a51
updated text in readme
Jul 10, 2024
b120682
updated example and added preinstall script
Jul 18, 2024
6b7e7a0
added checks parameter
Jul 19, 2024
284b31c
added checks parameter
Jul 19, 2024
5458559
added checks parameter
Jul 19, 2024
8761f45
updated matrix
Aug 5, 2024
43c8b63
updated secrets
Aug 5, 2024
b567a0c
updated secrets
Aug 5, 2024
7879087
updated to imagekitio-next
Aug 9, 2024
e3d5369
updated readme with abs
Aug 9, 2024
aa2ebce
updated package-lock
Aug 9, 2024
889a7c1
updated readme
Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Node CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
ahnv marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Setup module
run: |
npm install
env:
CI: true

e2e:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Setup module
run: |
npm install
npm run build
npm pack
- name: build example/app-router
run: |
cd example/app-router
echo NEXT_PUBLIC_URL_ENDPOINT = ${{ secrets.IK_URL_ENDPOINT }} > .env;
echo NEXT_PUBLIC_PUBLIC_KEY = ${{ secrets.IK_PUBLIC_KEY }} >> .env;
echo NEXT_PUBLIC_AUTHENTICATION_ENDPOINT = 'http://localhost:3000/api/auth' >> .env;
echo PRIVATE_KEY = ${{ secrets.IK_PRIVATE_KEY }} >> .env;
npm install && npm run build
env:
CI: true
NEXT_PUBLIC_PUBLIC_KEY: ${{ secrets.IK_PUBLIC_KEY }}
PRIVATE_KEY: ${{ secrets.IK_PRIVATE_KEY }}
NEXT_PUBLIC_URL_ENDPOINT: ${{ secrets.IK_URL_ENDPOINT }}

- name: Run E2E tests
uses: cypress-io/github-action@v4
with:
start: npm run serve:app-router
wait-on: 'http://localhost:3000'
env:
DEBUG: 'cypress:server:browsers:electron'
CI: true
NEXT_PUBLIC_PUBLIC_KEY: ${{ secrets.IK_PUBLIC_KEY }}
PRIVATE_KEY: ${{ secrets.IK_PRIVATE_KEY }}
NEXT_PUBLIC_URL_ENDPOINT: ${{ secrets.IK_URL_ENDPOINT }}

- name: tar workspace
if: always()
run: |
tar -cf build.tar --exclude=./build.tar .
- name: Archive build details
if: always()
uses: actions/upload-artifact@v3
with:
name: e2e-archive
path: build.tar
retention-days: 1
49 changes: 49 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
ahnv marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm i
npm run build
env:
CI: true
NEXT_PUBLIC_PUBLIC_KEY: ${{ secrets.ik_public_key }}
PRIVATE_KEY: ${{ secrets.ik_private_key }}
NEXT_PUBLIC_URL_ENDPOINT: ${{ secrets.ik_url_endopint }}


publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- name: npm publish
run: |
npm i
npm run build
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
CI: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.DS_Store
.env
.vscode
lib
dist
coverage
.DS_Store
779 changes: 779 additions & 0 deletions README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from "cypress";

export default defineConfig({
fixturesFolder: 'cypress/fixtures',
screenshotsFolder: 'screenshots',
videosFolder: 'videos',
env: {
APP_HOST: 'http://localhost:3000/',
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/index.ts',
},
});
112 changes: 112 additions & 0 deletions cypress/e2e/IKImage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
describe("ImageKit Next SDK", () => {
const APP_HOST = Cypress.env().APP_HOST;

describe("Lazyload", () => {
it("should have empty src before reaching lazyload threshold", () => {
cy.visit(APP_HOST);

cy.get(".lazyload").should("have.attr", "src").and("equal", "");
});

it("should have actual src after reaching lazyload threshold", () => {
cy.visit(APP_HOST);

cy.get(".lazyload").scrollIntoView();

cy.wait(500);

cy.get(".lazyload").should("have.attr", "src").and("include", "tr:h-200,w-200/default-image.jpg");
});
});

describe("Lazyload with LQIP", () => {
it("should have lqip src before reaching threshold", () => {
cy.visit(APP_HOST);

cy.get(".lazyload-lqip").should("have.attr", "src").and("include", "");
});

it("should have actual src after reaching element", () => {
cy.visit(APP_HOST);

cy.get(".lazyload-lqip").scrollIntoView();

cy.wait(1000);

cy.get(".lazyload-lqip").should("have.attr", "src").and("include", "tr:h-200,w-200/default-image.jpg");
});
});

describe("LQIP", () => {
// unable to test this because actual image load always finishes too quickly
it.skip("should have lqip src before image is loaded", () => {
cy.visit(APP_HOST);

cy.get(".lqip").should("have.attr", "src").and("include", "tr:h-200,w-200:q-20,bl-10/default-image.jpg");
});

it("should have actual src after image is loaded", () => {
cy.visit(APP_HOST);

cy.get(".lqip").scrollIntoView();

cy.wait(500);

cy.get(".lqip").should("have.attr", "src").and("include", "tr:h-200,w-200/default-image.jpg");
});
});

describe("State update check", () => {
it("should update image src with chained transformation outside ImageKitProvider dynamically", () => {
cy.visit(APP_HOST);

cy.get(".img-transformation-direct").scrollIntoView();

cy.wait(500);

cy.get(".img-transformation-direct").should("have.attr", "src").and("include", "tr:h-300,w-300/default-image.jpg");

cy.get(".btn-to-change-tr-direct").click();
cy.wait(500);

cy.get(".img-transformation-direct").should("have.attr", "src").and("include", "tr:h-200,w-600,r-max:h-200,w-200,rt-180/default-image.jpg");
});
it("should update image src within ImageKitProvider when button is clicked", () => {
cy.visit(APP_HOST);

cy.get(".img-transformation").scrollIntoView();

cy.wait(500);

cy.get(".img-transformation").should("have.attr", "src").and("include", "tr:h-200,w-200/default-image.jpg");

cy.get(".btn-to-change-tr").click();
cy.wait(500);

cy.get(".img-transformation").should("have.attr", "src").and("include", "tr:h-200,w-200,r-max/default-image.jpg");
});
});

describe("Height Width and Quality handling check", () => {
it("If height, width, or quality is specified only as a prop and not in the transformation, it is automatically applied in the transformation", () => {
cy.visit(APP_HOST);

cy.get(".applied-to-transformation").scrollIntoView();

cy.wait(500);

cy.get(".applied-to-transformation").should("have.attr", "src").and("include", "tr:h-200,w-200,q-10/default-image.jpg");
});
it("Height and width properties are ignored if they are included in the transformation", () => {
cy.visit(APP_HOST);

cy.get(".img-transformation-direct").scrollIntoView();

cy.wait(500);

cy.get(".img-transformation-direct").should("have.attr", "src").and("include", "tr:h-300,w-300/default-image.jpg");
cy.get(".img-transformation-direct").should("not.have.attr", "height");
cy.get(".img-transformation-direct").should("not.have.attr", "width");
});
});
});
51 changes: 51 additions & 0 deletions cypress/e2e/IKUpload.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe('IKUpload Element', () => {
const APP_HOST = Cypress.env().APP_HOST;

describe('Image Upload', () => {
it('should upload image and render same image', () => {
//static file
const p = 'sample.jpeg'

// launch URL
cy.visit(APP_HOST);

//upload file with attachFile
cy.get('.file-upload-ik').attachFile(p)

// wait for 4 secs
cy.wait(5000);

//Verify uploaded file
cy.get('.uploaded-img-ik').should('have.attr', 'src');
cy.get('.uploaded-img-ik').invoke('attr', 'src').should('not.equal', '');


// wait for 4 secs
cy.wait(4000);

cy.get('.state-value').invoke('val').then((val:any) => {
const stateValue = JSON.parse(val);
cy.log(JSON.stringify(stateValue, null, 2));
expect(stateValue.overrideParametersValue.fileNameOnLocalSystem).to.be.eq("sample.jpeg"); // This asserts that the file object was passed to the onOverrideParameters callback
expect(stateValue.uploadedImageSource).contains("sample-folder/overridden-file-name"); // This asserts that onOverrideParameters changed fileName parameter before upload
});
});

it('should upload non-image file and try to get error element', () => {
//static file
const p = 'example.json'

// launch URL
cy.visit(APP_HOST);

//upload file with attachFile
cy.get('.file-upload-error').attachFile(p)

// wait for 2 secs
cy.wait(2000);

//Verify uploaded file
cy.get('.upload-error-ik').should('contain', 'File upload failed.')
});
});
});
31 changes: 31 additions & 0 deletions cypress/e2e/IKVideo.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('IKVideo Element', () => {
const APP_HOST = Cypress.env().APP_HOST;

describe('Video transformation', () => {
it('should have element with transformation', () => {
cy.visit(APP_HOST);

cy.get('.ikvideo-default').scrollIntoView();

cy.wait(1000);

cy.get('.ikvideo-default > source')
.should('have.attr', 'src')
.and('include', 'tr:h-200,w-200/sample-video.mp4');
});
});

describe('Advance transformation', () => {
it('should have element with advance transformation', () => {
cy.visit(APP_HOST);

cy.get('.ikvideo-with-tr').scrollIntoView();

cy.wait(500);

cy.get('.ikvideo-with-tr > source')
.should('have.attr', 'src')
.and('include', 'tr:h-200,w-600,b-5_red,q-95/sample-video.mp4');
});
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Binary file added cypress/fixtures/sample.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading