Skip to content

Commit fdf811d

Browse files
chore: add-harness-tests
1 parent 772ed25 commit fdf811d

8 files changed

Lines changed: 250 additions & 256 deletions

example/.harness/manifest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
global.RN_HARNESS = {
2-
appRegistryComponentName: 'NitroImageExample',
3-
disableViewFlattening: false,
4-
};
1+
global.RN_HARNESS = {
2+
appRegistryComponentName: 'NitroImageExample',
3+
disableViewFlattening: false,
4+
}
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
import { describe, it, expect } from 'react-native-harness';
2-
import { Images } from 'react-native-nitro-image';
1+
import { describe, expect, it } from 'react-native-harness'
2+
import { Images } from 'react-native-nitro-image'
33

44
const makeImage = () =>
5-
Images.createBlankImage(16, 16, false, { r: 0, g: 0, b: 1, a: 1 });
5+
Images.createBlankImage(16, 16, false, { r: 0, g: 0, b: 1, a: 1 })
66

77
describe('Image - toRawPixelData', () => {
88
it('returns a non-empty pixel buffer with matching dimensions', () => {
9-
const image = makeImage();
10-
const raw = image.toRawPixelData();
11-
expect(raw.width).toBe(16);
12-
expect(raw.height).toBe(16);
13-
expect(raw.buffer.byteLength).toBeGreaterThan(0);
14-
expect(typeof raw.pixelFormat).toBe('string');
15-
});
9+
const image = makeImage()
10+
const raw = image.toRawPixelData()
11+
expect(raw.width).toBe(16)
12+
expect(raw.height).toBe(16)
13+
expect(raw.buffer.byteLength).toBeGreaterThan(0)
14+
expect(typeof raw.pixelFormat).toBe('string')
15+
})
1616

1717
it('toRawPixelDataAsync resolves with pixel data', async () => {
18-
const image = makeImage();
19-
const raw = await image.toRawPixelDataAsync();
20-
expect(raw.buffer.byteLength).toBeGreaterThan(0);
21-
});
22-
});
18+
const image = makeImage()
19+
const raw = await image.toRawPixelDataAsync()
20+
expect(raw.buffer.byteLength).toBeGreaterThan(0)
21+
})
22+
})
2323

2424
describe('Image - toEncodedImageData', () => {
2525
it('encodes to PNG', () => {
26-
const image = makeImage();
27-
const encoded = image.toEncodedImageData('png');
28-
expect(encoded.imageFormat).toBe('png');
29-
expect(encoded.width).toBe(16);
30-
expect(encoded.height).toBe(16);
31-
expect(encoded.buffer.byteLength).toBeGreaterThan(0);
32-
});
26+
const image = makeImage()
27+
const encoded = image.toEncodedImageData('png')
28+
expect(encoded.imageFormat).toBe('png')
29+
expect(encoded.width).toBe(16)
30+
expect(encoded.height).toBe(16)
31+
expect(encoded.buffer.byteLength).toBeGreaterThan(0)
32+
})
3333

3434
it('encodes to JPEG with quality', async () => {
35-
const image = makeImage();
36-
const encoded = await image.toEncodedImageDataAsync('jpg', 70);
37-
expect(encoded.imageFormat).toBe('jpg');
38-
expect(encoded.buffer.byteLength).toBeGreaterThan(0);
39-
});
40-
});
35+
const image = makeImage()
36+
const encoded = await image.toEncodedImageDataAsync('jpg', 70)
37+
expect(encoded.imageFormat).toBe('jpg')
38+
expect(encoded.buffer.byteLength).toBeGreaterThan(0)
39+
})
40+
})
4141

4242
describe('Images - loadFromEncodedImageData', () => {
4343
it('round-trips through PNG encoding', () => {
44-
const image = makeImage();
45-
const encoded = image.toEncodedImageData('png');
46-
const decoded = Images.loadFromEncodedImageData(encoded);
47-
expect(decoded.width).toBe(image.width);
48-
expect(decoded.height).toBe(image.height);
49-
});
50-
});
44+
const image = makeImage()
45+
const encoded = image.toEncodedImageData('png')
46+
const decoded = Images.loadFromEncodedImageData(encoded)
47+
expect(decoded.width).toBe(image.width)
48+
expect(decoded.height).toBe(image.height)
49+
})
50+
})
5151

5252
describe('Image - saveToTemporaryFileAsync', () => {
5353
it('writes a JPG to a temporary path', async () => {
54-
const image = makeImage();
55-
const path = await image.saveToTemporaryFileAsync('jpg', 80);
56-
expect(typeof path).toBe('string');
57-
expect(path.length).toBeGreaterThan(0);
58-
});
59-
});
54+
const image = makeImage()
55+
const path = await image.saveToTemporaryFileAsync('jpg', 80)
56+
expect(typeof path).toBe('string')
57+
expect(path.length).toBeGreaterThan(0)
58+
})
59+
})
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
import { describe, it, expect } from 'react-native-harness';
2-
import { Images } from 'react-native-nitro-image';
1+
import { describe, expect, it } from 'react-native-harness'
2+
import { Images } from 'react-native-nitro-image'
33

44
const makeImage = (w = 32, h = 32) =>
5-
Images.createBlankImage(w, h, true, { r: 0, g: 1, b: 0, a: 1 });
5+
Images.createBlankImage(w, h, true, { r: 0, g: 1, b: 0, a: 1 })
66

77
describe('Image - resize', () => {
88
it('resizes synchronously to the requested dimensions', () => {
9-
const image = makeImage(40, 20);
10-
const resized = image.resize(20, 10);
11-
expect(resized.width).toBe(20);
12-
expect(resized.height).toBe(10);
13-
});
9+
const image = makeImage(40, 20)
10+
const resized = image.resize(20, 10)
11+
expect(resized.width).toBe(20)
12+
expect(resized.height).toBe(10)
13+
})
1414

1515
it('resizes asynchronously to the requested dimensions', async () => {
16-
const image = makeImage(40, 20);
17-
const resized = await image.resizeAsync(80, 40);
18-
expect(resized.width).toBe(80);
19-
expect(resized.height).toBe(40);
20-
});
21-
});
16+
const image = makeImage(40, 20)
17+
const resized = await image.resizeAsync(80, 40)
18+
expect(resized.width).toBe(80)
19+
expect(resized.height).toBe(40)
20+
})
21+
})
2222

2323
describe('Image - crop', () => {
2424
it('crops to a sub-region', () => {
25-
const image = makeImage(100, 100);
26-
const cropped = image.crop(10, 10, 50, 50);
27-
expect(cropped.width).toBe(40);
28-
expect(cropped.height).toBe(40);
29-
});
30-
});
25+
const image = makeImage(100, 100)
26+
const cropped = image.crop(10, 10, 50, 50)
27+
expect(cropped.width).toBe(40)
28+
expect(cropped.height).toBe(40)
29+
})
30+
})
3131

3232
describe('Image - rotate', () => {
3333
it('rotates 90 degrees and returns an Image', () => {
34-
const image = makeImage(40, 20);
35-
const rotated = image.rotate(90);
36-
expect(rotated.width).toBeGreaterThan(0);
37-
expect(rotated.height).toBeGreaterThan(0);
38-
});
34+
const image = makeImage(40, 20)
35+
const rotated = image.rotate(90)
36+
expect(rotated.width).toBeGreaterThan(0)
37+
expect(rotated.height).toBeGreaterThan(0)
38+
})
3939

4040
it('rotates 180 degrees and preserves dimensions', () => {
41-
const image = makeImage(40, 20);
42-
const rotated = image.rotate(180);
43-
expect(rotated.width).toBe(40);
44-
expect(rotated.height).toBe(20);
45-
});
46-
});
41+
const image = makeImage(40, 20)
42+
const rotated = image.rotate(180)
43+
expect(rotated.width).toBe(40)
44+
expect(rotated.height).toBe(20)
45+
})
46+
})
4747

4848
describe('Image - mirrorHorizontally', () => {
4949
it('preserves dimensions when mirroring', () => {
50-
const image = makeImage(30, 20);
51-
const mirrored = image.mirrorHorizontally();
52-
expect(mirrored.width).toBe(30);
53-
expect(mirrored.height).toBe(20);
54-
});
55-
});
50+
const image = makeImage(30, 20)
51+
const mirrored = image.mirrorHorizontally()
52+
expect(mirrored.width).toBe(30)
53+
expect(mirrored.height).toBe(20)
54+
})
55+
})
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { describe, it, expect } from 'react-native-harness';
1+
import { describe, expect, it } from 'react-native-harness'
22
import {
33
Images,
44
supportsHeicLoading,
55
supportsHeicWriting,
6-
thumbHashToBase64String,
76
thumbHashFromBase64String,
8-
} from 'react-native-nitro-image';
7+
thumbHashToBase64String,
8+
} from 'react-native-nitro-image'
99

1010
describe('ImageUtils - HEIC support flags', () => {
1111
it('exposes booleans for HEIC loading and writing', () => {
12-
expect(typeof supportsHeicLoading).toBe('boolean');
13-
expect(typeof supportsHeicWriting).toBe('boolean');
14-
});
15-
});
12+
expect(typeof supportsHeicLoading).toBe('boolean')
13+
expect(typeof supportsHeicWriting).toBe('boolean')
14+
})
15+
})
1616

1717
describe('ImageUtils - thumbHash round-trip', () => {
1818
it('encodes a small image to a thumbHash and converts to base64', () => {
@@ -21,29 +21,29 @@ describe('ImageUtils - thumbHash round-trip', () => {
2121
g: 0.2,
2222
b: 0.8,
2323
a: 1,
24-
});
25-
const small = image.resize(32, 32);
26-
const hash = small.toThumbHash();
27-
expect(hash.byteLength).toBeGreaterThan(0);
24+
})
25+
const small = image.resize(32, 32)
26+
const hash = small.toThumbHash()
27+
expect(hash.byteLength).toBeGreaterThan(0)
2828

29-
const base64 = thumbHashToBase64String(hash);
30-
expect(typeof base64).toBe('string');
31-
expect(base64.length).toBeGreaterThan(0);
29+
const base64 = thumbHashToBase64String(hash)
30+
expect(typeof base64).toBe('string')
31+
expect(base64.length).toBeGreaterThan(0)
3232

33-
const restored = thumbHashFromBase64String(base64);
34-
expect(restored.byteLength).toBe(hash.byteLength);
35-
});
33+
const restored = thumbHashFromBase64String(base64)
34+
expect(restored.byteLength).toBe(hash.byteLength)
35+
})
3636

3737
it('decodes thumbHash bytes back into an Image', () => {
3838
const image = Images.createBlankImage(32, 32, true, {
3939
r: 1,
4040
g: 0,
4141
b: 0,
4242
a: 1,
43-
});
44-
const hash = image.toThumbHash();
45-
const decoded = Images.loadFromThumbHash(hash);
46-
expect(decoded.width).toBeGreaterThan(0);
47-
expect(decoded.height).toBeGreaterThan(0);
48-
});
49-
});
43+
})
44+
const hash = image.toThumbHash()
45+
const decoded = Images.loadFromThumbHash(hash)
46+
expect(decoded.width).toBeGreaterThan(0)
47+
expect(decoded.height).toBeGreaterThan(0)
48+
})
49+
})
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import { describe, it, expect } from 'react-native-harness';
2-
import { Images } from 'react-native-nitro-image';
1+
import { describe, expect, it } from 'react-native-harness'
2+
import { Images } from 'react-native-nitro-image'
33

44
describe('Images - createBlankImage', () => {
55
it('creates a blank image with the requested dimensions', () => {
6-
const image = Images.createBlankImage(64, 32, false);
7-
expect(image.width).toBe(64);
8-
expect(image.height).toBe(32);
9-
});
6+
const image = Images.createBlankImage(64, 32, false)
7+
expect(image.width).toBe(64)
8+
expect(image.height).toBe(32)
9+
})
1010

1111
it('creates a blank image with alpha enabled', () => {
12-
const image = Images.createBlankImage(16, 16, true);
13-
expect(image.width).toBe(16);
14-
expect(image.height).toBe(16);
15-
});
12+
const image = Images.createBlankImage(16, 16, true)
13+
expect(image.width).toBe(16)
14+
expect(image.height).toBe(16)
15+
})
1616

1717
it('fills the image with a solid color when fill is provided', () => {
1818
const image = Images.createBlankImage(8, 8, true, {
1919
r: 1,
2020
g: 0,
2121
b: 0,
2222
a: 1,
23-
});
24-
const raw = image.toRawPixelData();
25-
expect(raw.width).toBe(8);
26-
expect(raw.height).toBe(8);
27-
expect(raw.buffer.byteLength).toBeGreaterThan(0);
28-
});
29-
});
23+
})
24+
const raw = image.toRawPixelData()
25+
expect(raw.width).toBe(8)
26+
expect(raw.height).toBe(8)
27+
expect(raw.buffer.byteLength).toBeGreaterThan(0)
28+
})
29+
})
3030

3131
describe('Images - createBlankImageAsync', () => {
3232
it('resolves with an Image of the requested size', async () => {
33-
const image = await Images.createBlankImageAsync(20, 10, false);
34-
expect(image.width).toBe(20);
35-
expect(image.height).toBe(10);
36-
});
37-
});
33+
const image = await Images.createBlankImageAsync(20, 10, false)
34+
expect(image.width).toBe(20)
35+
expect(image.height).toBe(10)
36+
})
37+
})

0 commit comments

Comments
 (0)