-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check image size betweenness, add argument tests (#74)
* fix: tests to care windows/others display resolution diff * fix: testing import cjs to esm * fix: check image size betweenness, add argument tests * fix: move call fn to test's lib --------- Co-authored-by: Alvaro Cabrera Durán <[email protected]>
- Loading branch information
1 parent
7834d1c
commit 14d44dd
Showing
4 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { existsSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
|
||
import sizeOf from 'image-size'; | ||
import { rimrafSync } from 'rimraf'; | ||
|
||
import { | ||
getBaseUrl, fixedSize, fixedFile, callTC, | ||
} from '../lib'; | ||
|
||
fixture('Testing cli --take-snapshot').page(getBaseUrl()); | ||
|
||
test('should care arg without name', async t => { | ||
const basePath = join('e2e', 'screens', 'Testing_cli', 'assert__it'); | ||
rimrafSync(basePath); | ||
|
||
await callTC('e2e/file/cases/takesnapshot.test.js', ['--take-snapshot', 'base', '-t', 'takesnapshot']); | ||
|
||
await t.expect(existsSync(join(basePath, fixedFile('base.png')))).ok(); | ||
}); | ||
|
||
test('should care arg with name', async t => { | ||
const basePath = join('e2e', 'screens', 'Testing_cli', 'assert__it'); | ||
rimrafSync(basePath); | ||
|
||
const fpath = 'e2e/file/cases/takesnapshot.test.js'; | ||
await callTC(fpath, ['--take-snapshot', 'base', '-t', 'takesnapshot']); | ||
await callTC(fpath, ['--take-snapshot', 'actual', '-t', 'takesnapshot']); | ||
await callTC(fpath, ['--take-snapshot', 'foo', '-t', 'takesnapshot']); | ||
|
||
await t.expect(existsSync(join(basePath, fixedFile('base.png')))).ok(); | ||
await t.expect(existsSync(join(basePath, fixedFile('actual.png')))).ok(); | ||
await t.expect(existsSync(join(basePath, fixedFile('foo.png')))).ok(); | ||
await t.expect(existsSync(join(basePath, fixedFile('bar.png')))).notOk(); | ||
}); | ||
|
||
fixture('Testing cli --full-page').page(getBaseUrl()); | ||
|
||
test('should care arg', async t => { | ||
const basePath = join('e2e', 'screens', 'Testing_cli'); | ||
rimrafSync(basePath); | ||
|
||
const fpath = 'e2e/file/cases/takesnapshot.test.js'; | ||
await callTC(fpath, ['--take-snapshot', '--full-page', '-t', 'fullpage']); | ||
await callTC(fpath, ['--take-snapshot', '-t', 'nofullpage']); | ||
|
||
const pngFull = sizeOf(join(basePath, 'assert__it__with__fullpage', fixedFile('base.png'))); | ||
await t.expect(pngFull.width).eql(fixedSize(1290)); | ||
await t.expect(pngFull.height).gte(fixedSize(1356)); | ||
|
||
const pngNoFull = sizeOf(join(basePath, 'assert__it__without__fullpage', fixedFile('base.png'))); | ||
await t.expect(pngNoFull.width).gte(fixedSize(623)); | ||
await t.expect(pngNoFull.width).lte(fixedSize(640)); | ||
await t.expect(pngNoFull.height).gte(fixedSize(463)); | ||
await t.expect(pngNoFull.height).lte(fixedSize(480)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getBaseUrl } from '../../lib'; | ||
import { takeSnapshot } from '../../../lib'; | ||
|
||
fixture('Testing cli').page(getBaseUrl()); | ||
|
||
test('takesnapshot', async t => { | ||
await takeSnapshot(t, 'assert_it'); | ||
}); | ||
|
||
test('fullpage', async t => { | ||
await t.resizeWindow(640, 480); | ||
await takeSnapshot(t, 'assert_it_with_fullpage'); | ||
}); | ||
|
||
test('nofullpage', async t => { | ||
await t.resizeWindow(640, 480); | ||
await takeSnapshot(t, 'assert_it_without_fullpage'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { spawn } from 'node:child_process'; | ||
import process from 'node:process'; | ||
|
||
// this enforces a particular DPI to allow | ||
// tests to behave in a deterministic way!! | ||
process.env.WINDOW_DPI = process.env.WINDOW_DPI || '2'; | ||
|
||
function getBaseUrl() { | ||
return `${process.env.BASE_URL}/`; | ||
} | ||
|
||
function fixedSize(value) { | ||
return value * process.env.WINDOW_DPI; | ||
} | ||
|
||
function fixedFile(name) { | ||
if (process.env.WINDOW_DPI > 1) { | ||
return name.replace('.', `@${process.env.WINDOW_DPI}.`); | ||
} | ||
return name; | ||
} | ||
|
||
function callNpx(args) { | ||
const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx'; | ||
|
||
return new Promise(function fn(resolve) { | ||
const cmd = spawn(npx, args, { shell: true, stdio: 'inherit' }); | ||
|
||
cmd.on('close', function onClose() { | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function callTC(targetTest, additionalArgs) { | ||
const browser = process.env.BROWSER != null ? process.env.BROWSER : 'chrome:headless'; | ||
const baseArgs = ['testcafe', browser, targetTest, '-s', 'path=e2e/screens', '-q']; | ||
return callNpx(baseArgs.concat(additionalArgs)); | ||
} | ||
|
||
export { | ||
getBaseUrl, fixedSize, fixedFile, callTC, | ||
}; |