Skip to content

Commit bb53df3

Browse files
authored
fix: exception on initialization for NgModule projects (#55)
* fix: fixed an issue causing an exception on initialization * ci: fixed error with prepublish script * test: added e2e tests with docker and cypress * Feature/ci setup GitHub actions (#53) * chore(demo): add `to-px` as devDependency * test: update test file structure and scripts * ci(actions): set up * ci(actions): fix yaml * ci(actions): fix path to workspace inside container * ci(actions): remove `\"`from version en var to fix CI error * chore: bump version to 6.1.2 * chore(package.json): update scripts * test: improved test script to use images with different angular versions * test(home): updated module to enable testing non-standalone projects * ci(test): added job for testing compatibility with angular v16
1 parent 43e9483 commit bb53df3

File tree

15 files changed

+4199
-1663
lines changed

15 files changed

+4199
-1663
lines changed

.github/workflows/run-tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
PKG_VERSION=$(cd $GITHUB_WORKSPACE/dist/ionic-header-parallax && npm pkg get version | tr -d '"')
3+
mkdir cypress
4+
cp -r $GITHUB_WORKSPACE/cypress/* ./cypress
5+
cp $GITHUB_WORKSPACE/cypress.config.ts .
6+
cp -r $GITHUB_WORKSPACE/src/app/home/* ./src/app/home
7+
npm i $GITHUB_WORKSPACE/dist/ionic-header-parallax-$PKG_VERSION.tgz
8+
cypress install
9+
ng serve --host 0.0.0.0 --port 4200 & \
10+
(wait-on http://0.0.0.0:4200 --timeout 30000 --interval 1000 && cypress run --headless) \
11+
|| { echo 'Angular server failed to start'; exit 1; }

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Run Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test-angular19:
7+
runs-on: ubuntu-latest
8+
container:
9+
image: raschidjfr/ionic-blank:ionic8-angular19-cypress14
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Install dependencies
16+
run: npm ci
17+
18+
- name: Build project
19+
run: npm run build
20+
21+
- name: Run tests
22+
working-directory: /app
23+
run: bash $GITHUB_WORKSPACE/.github/workflows/run-tests.sh
24+
25+
test-angular16:
26+
runs-on: ubuntu-latest
27+
container:
28+
image: raschidjfr/ionic-blank:ionic8-angular16-cypress14
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Build project
38+
run: npm run build
39+
40+
- name: Run tests
41+
working-directory: /app
42+
run: bash $GITHUB_WORKSPACE/.github/workflows/run-tests.sh

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ In the root folder:
1010
1. Run `npm run link` to point the demo app to use the local directive's source.
1111
2. Run `ng serve` to launch the demo app.
1212

13+
### Test
14+
1. Build: `npm run build`
15+
2. Test with Docker: `bin/test.sh`
16+
17+

bin/test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Use this to test the angular project with cypress.
3+
# Execute from the project's root folder.
4+
# Usage: bin/test.sh [angular_version]
5+
6+
get_lib_version() {
7+
echo $(cd dist/ionic-header-parallax && npm pkg get version)
8+
}
9+
10+
run_test() {
11+
ng_version=$1
12+
lib_version=$(get_lib_version)
13+
docker run \
14+
--rm \
15+
-ti \
16+
-v "$PWD:/project" \
17+
-v "$PWD/dist:/dist" \
18+
raschidjfr/ionic-blank:ionic8-angular$ng_version-cypress14 \
19+
bash -c "\
20+
mkdir cypress \
21+
&& cp -r /project/cypress/* ./cypress \
22+
&& cp /project/cypress.config.ts . \
23+
&& cp -r /project/src/app/home/* ./src/app/home \
24+
&& npm i /dist/ionic-header-parallax-$lib_version.tgz \
25+
&& (ng serve --host 0.0.0.0 --port 4200 \
26+
& (wait-on http://0.0.0.0:4200 && cypress run --headless) \
27+
|| { echo 'Angular server failed to start'; exit 1; })"
28+
}
29+
30+
ng_version="${1:-19}"
31+
echo "Testing library in Ionic v8 and Angular v$ng_version..."
32+
run_test $ng_version

cypress.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
5+
e2e: {
6+
baseUrl: 'http://0.0.0.0:4200',
7+
supportFile: false
8+
},
9+
10+
11+
component: {
12+
devServer: {
13+
framework: 'angular',
14+
bundler: 'webpack',
15+
},
16+
specPattern: '**/*.cy.ts'
17+
}
18+
19+
})

cypress/e2e/spec.cy.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('Ionic Header Parallax', () => {
2+
it('Main component can load', () => {
3+
cy.visit('/');
4+
cy.contains('Start with Ionic UI Components');
5+
});
6+
7+
it('Parallax effect works', () => {
8+
cy.visit('/');
9+
cy.wait(200);
10+
11+
cy.get('ion-header').should('have.css', 'height', '300px');
12+
cy.get('ion-content').shadow().find('.inner-scroll').scrollTo('bottom');
13+
cy.get('ion-header').invoke('height').should('be.lessThan', 60);
14+
});
15+
});

cypress/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["**/*.ts"],
4+
"compilerOptions": {
5+
"sourceMap": false,
6+
"types": ["cypress"]
7+
}
8+
}

0 commit comments

Comments
 (0)