Skip to content

Commit

Permalink
Add node-test using jest
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Jan 8, 2021
1 parent 2408e7d commit 51c0606
Show file tree
Hide file tree
Showing 5 changed files with 1,157 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ module.exports = {
},
// node test files
{
files: ['addon-tests/**/*.js', 'fastboot-tests/**/*.js'],
files: ['node-tests/**/*.js'],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
mocha: true,
jest: true,
},
plugins: ['node'],
rules: Object.assign(
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ jobs:
- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Test
- name: Test Ember
run: yarn test:ember --launch ${{ matrix.browser }}

- name: Test Image Processing
run: yarn test:node


floating-dependencies:
name: Floating Dependencies
Expand Down Expand Up @@ -129,6 +132,9 @@ jobs:
- name: Test
run: yarn test:ember --launch ${{ matrix.browser }}

- name: Test Image Processing
run: yarn test:node


try-scenarios:
name: Tests - ${{ matrix.ember-try-scenario }}
Expand Down
56 changes: 56 additions & 0 deletions node-tests/generate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const sharp = require('sharp');
const jpegquality = require('jpegquality');
const execa = require('execa');
const fs = require('fs');
const path = require('path');

const hash = '00e24234f1b58e32b935b1041432916f';
const images = [
{
file: 'test.jpg',
type: 'image/jpeg',
alpha: false,
jpeqQuality: 50,
},
{
file: 'test.png',
type: 'image/png',
alpha: true,
},
];
const sizes = [50, 100];
const aspectRatio = 2;
const appDir = './dist';

beforeAll(function () {
jest.setTimeout(300000);
return execa('./node_modules/ember-cli/bin/ember', ['build']);
});

images.forEach((img) => {
sizes.forEach((width) => {
test(`loads image ${img.file} ${width}w`, async function () {
const [name, ext] = img.file.split(['.']);

const imageData = fs.readFileSync(
path.join(
appDir,
`assets/images/responsive/${name}${width}w-${hash}.${ext}`
)
);

const meta = await sharp(imageData).metadata();

expect(meta).toBeDefined();
expect(meta.width).toEqual(width);
expect(meta.height).toEqual(Math.round(width / aspectRatio));
expect(meta.format).toEqual(img.type.split('/')[1]);
expect(meta.hasAlpha).toEqual(img.alpha);
expect(meta.hasProfile).toEqual(false);

if (img.jpeqQuality) {
expect(Math.round(jpegquality(imageData))).toEqual(img.jpeqQuality);
}
});
});
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"start": "ember serve",
"test": "npm-run-all lint test:*",
"test:ember": "ember test",
"test:ember-compatibility": "ember try:each"
"test:ember-compatibility": "ember try:each",
"test:node": "jest node-tests"
},
"dependencies": {
"async-q": "^0.3.1",
Expand Down Expand Up @@ -69,6 +70,8 @@
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"execa": "^5.0.0",
"jest": "^26.6.3",
"jpegquality": "^0.1.7",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
Expand Down
Loading

0 comments on commit 51c0606

Please sign in to comment.