fix: package lock fingerprint

This commit is contained in:
nuno maduro
2026-07-18 01:10:01 +01:00
parent 9e79e491e2
commit 820fa08313
237 changed files with 2409 additions and 2100 deletions
@@ -2,7 +2,7 @@
use Pest\Plugins\Concerns\HandleArguments;
test('method hasArgument', function (string $argument, bool $expectedResult) {
test('method hasArgument', function (string $argument, bool $expectedResult): void {
$obj = new class
{
use HandleArguments;
@@ -25,7 +25,7 @@ test('method hasArgument', function (string $argument, bool $expectedResult) {
['--undefined-argument', false],
]);
test('popArgument preserves duplicate values when removing a missing argument', function () {
test('popArgument preserves duplicate values when removing a missing argument', function (): void {
$obj = new class
{
use HandleArguments;
@@ -37,7 +37,7 @@ test('popArgument preserves duplicate values when removing a missing argument',
expect($result)->toBe($arguments);
});
test('popArgument preserves duplicate values when removing an existing argument', function () {
test('popArgument preserves duplicate values when removing an existing argument', function (): void {
$obj = new class
{
use HandleArguments;
+2 -2
View File
@@ -2,7 +2,7 @@
use Pest\Plugins\Environment;
test('environment is set to CI when --ci option is used', function () {
test('environment is set to CI when --ci option is used', function (): void {
$previousName = Environment::name();
$plugin = new Environment;
@@ -14,7 +14,7 @@ test('environment is set to CI when --ci option is used', function () {
Environment::name($previousName);
});
test('environment is set to Local when --ci option is not used', function () {
test('environment is set to Local when --ci option is not used', function (): void {
$plugin = new Environment;
$plugin->handleArguments(['foo', 'bar', 'baz']);
+1 -1
View File
@@ -2,7 +2,7 @@
use Pest\Plugins\Retry;
it('orders by defects and stop on defects if when --retry is used ', function () {
it('orders by defects and stop on defects if when --retry is used ', function (): void {
$retry = new Retry;
$arguments = $retry->handleArguments(['--retry']);
+40 -40
View File
@@ -5,8 +5,8 @@ use Pest\Plugins\Shard;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\BufferedOutput;
describe('getShard', function () {
it('parses valid shard format', function (string $format, int $expectedIndex, int $expectedTotal) {
describe('getShard', function (): void {
it('parses valid shard format', function (string $format, int $expectedIndex, int $expectedTotal): void {
$input = new ArgvInput(['test', '--shard', $format]);
$result = Shard::getShard($input);
@@ -25,7 +25,7 @@ describe('getShard', function () {
['5/100', 5, 100],
]);
it('throws exception for invalid format', function (array $arguments) {
it('throws exception for invalid format', function (array $arguments): void {
$input = new ArgvInput($arguments);
Shard::getShard($input);
@@ -38,7 +38,7 @@ describe('getShard', function () {
[['test', '--shard', '1.5/2']],
])->throws(InvalidOption::class);
it('throws exception for invalid index or total values', function (array $arguments) {
it('throws exception for invalid index or total values', function (array $arguments): void {
$input = new ArgvInput($arguments);
Shard::getShard($input);
@@ -50,8 +50,8 @@ describe('getShard', function () {
])->throws(InvalidOption::class);
});
describe('buildFilterArgument', function () {
it('generates compact filter for single test', function () {
describe('buildFilterArgument', function (): void {
it('generates compact filter for single test', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -63,7 +63,7 @@ describe('buildFilterArgument', function () {
expect($filter)->toBe('Tests\\\\Unit\\\\ExampleTest');
});
it('generates compact filter for multiple tests with common prefix', function () {
it('generates compact filter for multiple tests with common prefix', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -78,7 +78,7 @@ describe('buildFilterArgument', function () {
expect($filter)->toBe('Tests\\\\Unit\\\\Foo\\\\(BarTest|BazTest)');
});
it('generates compact filter for tests with different namespaces', function () {
it('generates compact filter for tests with different namespaces', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -93,7 +93,7 @@ describe('buildFilterArgument', function () {
expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest|Feature\\\\BarTest)');
});
it('returns empty string for empty test list', function () {
it('returns empty string for empty test list', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -102,10 +102,10 @@ describe('buildFilterArgument', function () {
$filter = $method->invoke($shard, []);
expect($filter)->toBe('');
expect($filter)->toBeEmpty();
});
it('generates compact filter for deeply nested namespaces', function () {
it('generates compact filter for deeply nested namespaces', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -121,7 +121,7 @@ describe('buildFilterArgument', function () {
expect($filter)->toBe('Tests\\\\Unit\\\\Plugins\\\\Concerns\\\\(Foo|Bar|Baz)');
});
it('handles mix of nested and flat namespaces', function () {
it('handles mix of nested and flat namespaces', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -142,8 +142,8 @@ describe('buildFilterArgument', function () {
});
});
describe('ensureFilterLengthIsSafe', function () {
it('accepts filter within length limit', function () {
describe('ensureFilterLengthIsSafe', function (): void {
it('accepts filter within length limit', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -157,7 +157,7 @@ describe('ensureFilterLengthIsSafe', function () {
expect(true)->toBeTrue();
});
it('throws exception when filter exceeds default limit', function () {
it('throws exception when filter exceeds default limit', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -169,7 +169,7 @@ describe('ensureFilterLengthIsSafe', function () {
$method->invoke($shard, $filter);
})->throws(InvalidOption::class, 'The generated filter for this shard is too long');
it('respects custom limit from environment variable', function () {
it('respects custom limit from environment variable', function (): void {
putenv('PEST_SHARD_MAX_FILTER_LENGTH=1000');
$output = new BufferedOutput;
@@ -191,7 +191,7 @@ describe('ensureFilterLengthIsSafe', function () {
}
});
it('accepts filter within custom limit', function () {
it('accepts filter within custom limit', function (): void {
putenv('PEST_SHARD_MAX_FILTER_LENGTH=1000');
$output = new BufferedOutput;
@@ -213,8 +213,8 @@ describe('ensureFilterLengthIsSafe', function () {
});
});
describe('handleArguments', function () {
it('returns original arguments when shard option is not present', function () {
describe('handleArguments', function (): void {
it('returns original arguments when shard option is not present', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -225,7 +225,7 @@ describe('handleArguments', function () {
expect($result)->toBe($arguments);
});
it('removes parallel arguments from test discovery', function () {
it('removes parallel arguments from test discovery', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -240,8 +240,8 @@ describe('handleArguments', function () {
});
});
describe('parseListTestsOutput', function () {
it('parses Tests\\ namespaced classes from --list-tests output', function () {
describe('parseListTestsOutput', function (): void {
it('parses Tests\\ namespaced classes from --list-tests output', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -262,7 +262,7 @@ OUT;
]);
});
it('deduplicates repeated class names from multiple test methods', function () {
it('deduplicates repeated class names from multiple test methods', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -278,18 +278,18 @@ OUT;
expect($method->invoke($shard, $listOutput))->toBe(['Tests\\Same']);
});
it('returns an empty list for output with no matching lines', function () {
it('returns an empty list for output with no matching lines', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
$reflection = new ReflectionClass($shard);
$method = $reflection->getMethod('parseListTestsOutput');
expect($method->invoke($shard, ''))->toBe([])
->and($method->invoke($shard, 'some random text'))->toBe([]);
expect($method->invoke($shard, ''))->toBeEmpty()
->and($method->invoke($shard, 'some random text'))->toBeEmpty();
});
it('parses non-Tests namespaced classes', function () {
it('parses non-Tests namespaced classes', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -309,7 +309,7 @@ OUT;
]);
});
it('parses unnamespaced top-level classes', function () {
it('parses unnamespaced top-level classes', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -319,7 +319,7 @@ OUT;
expect($method->invoke($shard, ' - P\FooTest::test_bar'))->toBe(['FooTest']);
});
it('strips the P\\ Pest prefix but keeps the rest of the FQCN', function () {
it('strips the P\\ Pest prefix but keeps the rest of the FQCN', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -337,7 +337,7 @@ OUT;
]);
});
it('ignores junk lines that lack the " - …::" framing', function () {
it('ignores junk lines that lack the " - …::" framing', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -356,8 +356,8 @@ OUT;
});
});
describe('buildListTestsCommand', function () {
it('builds the list-tests command with the forwarded --test-directory', function () {
describe('buildListTestsCommand', function (): void {
it('builds the list-tests command with the forwarded --test-directory', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -375,7 +375,7 @@ describe('buildListTestsCommand', function () {
]);
});
it('strips --parallel and -p when building the list-tests command', function () {
it('strips --parallel and -p when building the list-tests command', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -393,7 +393,7 @@ describe('buildListTestsCommand', function () {
]);
});
it('forwards --test-directory even when input arguments include one', function () {
it('forwards --test-directory even when input arguments include one', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -405,7 +405,7 @@ describe('buildListTestsCommand', function () {
expect($command)->toContain('--test-directory=suites');
});
it('strips --processes=N when building the list-tests command', function () {
it('strips --processes=N when building the list-tests command', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -423,7 +423,7 @@ describe('buildListTestsCommand', function () {
]);
});
it('strips --processes N (space-separated) when building the list-tests command', function () {
it('strips --processes N (space-separated) when building the list-tests command', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -438,8 +438,8 @@ describe('buildListTestsCommand', function () {
});
});
describe('addOutput', function () {
it('displays shard information after test execution', function () {
describe('addOutput', function (): void {
it('displays shard information after test execution', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -462,7 +462,7 @@ describe('addOutput', function () {
->and($outputText)->toContain('out of 100');
});
it('uses singular form for single test file', function () {
it('uses singular form for single test file', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
@@ -482,7 +482,7 @@ describe('addOutput', function () {
->and($outputText)->not->toContain('1 files');
});
it('returns original exit code when shard is not set', function () {
it('returns original exit code when shard is not set', function (): void {
$output = new BufferedOutput;
$shard = new Shard($output);
+41 -41
View File
@@ -2,12 +2,12 @@
use Pest\Plugins\Tia\ContentHash;
describe('of()', function () {
it('returns false when file does not exist', function () {
describe('of()', function (): void {
it('returns false when file does not exist', function (): void {
expect(ContentHash::of('/path/that/does/not/exist.php'))->toBeFalse();
});
it('hashes an existing file', function () {
it('hashes an existing file', function (): void {
$path = tempnam(sys_get_temp_dir(), 'pest_').'.php';
file_put_contents($path, "<?php echo 'hi';");
@@ -19,70 +19,70 @@ describe('of()', function () {
});
});
describe('PHP files', function () {
it('produces the same hash regardless of whitespace differences', function () {
describe('PHP files', function (): void {
it('produces the same hash regardless of whitespace differences', function (): void {
$a = ContentHash::ofContent('a.php', "<?php \$foo = 1;\n\necho \$foo;");
$b = ContentHash::ofContent('a.php', '<?php $foo=1; echo $foo;');
expect($a)->toBe($b);
});
it('ignores single-line comments', function () {
it('ignores single-line comments', function (): void {
$a = ContentHash::ofContent('a.php', "<?php\n// this is a comment\n\$foo = 1;");
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
expect($a)->toBe($b);
});
it('ignores hash-style comments', function () {
it('ignores hash-style comments', function (): void {
$a = ContentHash::ofContent('a.php', "<?php\n# hash comment\n\$foo = 1;");
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
expect($a)->toBe($b);
});
it('ignores multi-line comments', function () {
it('ignores multi-line comments', function (): void {
$a = ContentHash::ofContent('a.php', "<?php\n/* a multi\n line comment */\n\$foo = 1;");
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
expect($a)->toBe($b);
});
it('ignores doc comments', function () {
it('ignores doc comments', function (): void {
$a = ContentHash::ofContent('a.php', "<?php\n/**\n * @return int\n */\nfunction foo() { return 1; }");
$b = ContentHash::ofContent('a.php', "<?php\nfunction foo() { return 1; }");
expect($a)->toBe($b);
});
it('detects code changes', function () {
it('detects code changes', function (): void {
$a = ContentHash::ofContent('a.php', '<?php $foo = 1;');
$b = ContentHash::ofContent('a.php', '<?php $foo = 2;');
expect($a)->not->toBe($b);
});
it('preserves whitespace inside string literals', function () {
it('preserves whitespace inside string literals', function (): void {
$a = ContentHash::ofContent('a.php', "<?php \$foo = 'hello world';");
$b = ContentHash::ofContent('a.php', "<?php \$foo = 'helloworld';");
expect($a)->not->toBe($b);
});
it('treats variable renames as a change', function () {
it('treats variable renames as a change', function (): void {
$a = ContentHash::ofContent('a.php', '<?php $foo = 1;');
$b = ContentHash::ofContent('a.php', '<?php $bar = 1;');
expect($a)->not->toBe($b);
});
it('falls back to a raw hash for unparseable PHP', function () {
it('falls back to a raw hash for unparseable PHP', function (): void {
$hash = ContentHash::ofContent('a.php', 'not valid php at all');
expect($hash)->toBeString()->not->toBeEmpty();
});
it('is case-insensitive on the file extension', function () {
it('is case-insensitive on the file extension', function (): void {
$a = ContentHash::ofContent('a.PHP', "<?php\n// comment\n\$foo = 1;");
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
@@ -90,43 +90,43 @@ describe('PHP files', function () {
});
});
describe('Blade files', function () {
it('strips blade comments', function () {
describe('Blade files', function (): void {
it('strips blade comments', function (): void {
$a = ContentHash::ofContent('a.blade.php', '<div>{{-- a comment --}}Hello</div>');
$b = ContentHash::ofContent('a.blade.php', '<div>Hello</div>');
expect($a)->toBe($b);
});
it('strips multi-line blade comments', function () {
it('strips multi-line blade comments', function (): void {
$a = ContentHash::ofContent('a.blade.php', "<div>\n{{--\n multi\n line\n--}}\nHello\n</div>");
$b = ContentHash::ofContent('a.blade.php', '<div> Hello </div>');
expect($a)->toBe($b);
});
it('collapses whitespace', function () {
it('collapses whitespace', function (): void {
$a = ContentHash::ofContent('a.blade.php', "<div>\n Hello\n World\n</div>");
$b = ContentHash::ofContent('a.blade.php', '<div> Hello World </div>');
expect($a)->toBe($b);
});
it('detects content changes', function () {
it('detects content changes', function (): void {
$a = ContentHash::ofContent('a.blade.php', '<div>Hello</div>');
$b = ContentHash::ofContent('a.blade.php', '<div>Goodbye</div>');
expect($a)->not->toBe($b);
});
it('keeps blade directives intact', function () {
it('keeps blade directives intact', function (): void {
$a = ContentHash::ofContent('a.blade.php', '@if($user)Hi @endif');
$b = ContentHash::ofContent('a.blade.php', '@if($user)Bye @endif');
expect($a)->not->toBe($b);
});
it('does not use the PHP tokenizer for blade files', function () {
it('does not use the PHP tokenizer for blade files', function (): void {
$a = ContentHash::ofContent('a.blade.php', '<?php // not stripped ?> hello');
$b = ContentHash::ofContent('a.blade.php', '<?php ?> hello');
@@ -134,78 +134,78 @@ describe('Blade files', function () {
});
});
describe('JavaScript-like files', function () {
it('strips line comments', function () {
describe('JavaScript-like files', function (): void {
it('strips line comments', function (): void {
$a = ContentHash::ofContent('a.js', "// a comment\nconst foo = 1;");
$b = ContentHash::ofContent('a.js', 'const foo = 1;');
expect($a)->toBe($b);
});
it('strips block comments on their own lines', function () {
it('strips block comments on their own lines', function (): void {
$a = ContentHash::ofContent('a.js', "/* block */\nconst foo = 1;");
$b = ContentHash::ofContent('a.js', 'const foo = 1;');
expect($a)->toBe($b);
});
it('collapses whitespace', function () {
it('collapses whitespace', function (): void {
$a = ContentHash::ofContent('a.js', "const foo = 1;\n\nconst bar = 2;");
$b = ContentHash::ofContent('a.js', 'const foo = 1; const bar = 2;');
expect($a)->toBe($b);
});
it('detects code changes', function () {
it('detects code changes', function (): void {
$a = ContentHash::ofContent('a.js', 'const foo = 1;');
$b = ContentHash::ofContent('a.js', 'const foo = 2;');
expect($a)->not->toBe($b);
});
it('does not strip inline trailing comments', function () {
it('does not strip inline trailing comments', function (): void {
$a = ContentHash::ofContent('a.js', 'const foo = 1; // inline');
$b = ContentHash::ofContent('a.js', 'const foo = 1;');
expect($a)->not->toBe($b);
});
it('applies the same rules to .ts files', function () {
it('applies the same rules to .ts files', function (): void {
$a = ContentHash::ofContent('a.ts', "// comment\nconst foo: number = 1;");
$b = ContentHash::ofContent('a.ts', 'const foo: number = 1;');
expect($a)->toBe($b);
});
it('applies the same rules to .tsx files', function () {
it('applies the same rules to .tsx files', function (): void {
$a = ContentHash::ofContent('a.tsx', "// comment\nconst Foo = () => <div/>;");
$b = ContentHash::ofContent('a.tsx', 'const Foo = () => <div/>;');
expect($a)->toBe($b);
});
it('applies the same rules to .jsx files', function () {
it('applies the same rules to .jsx files', function (): void {
$a = ContentHash::ofContent('a.jsx', "// comment\nconst Foo = () => <div/>;");
$b = ContentHash::ofContent('a.jsx', 'const Foo = () => <div/>;');
expect($a)->toBe($b);
});
it('applies the same rules to .vue files', function () {
it('applies the same rules to .vue files', function (): void {
$a = ContentHash::ofContent('a.vue', "<script>\n// comment\nexport default {}\n</script>");
$b = ContentHash::ofContent('a.vue', '<script> export default {} </script>');
expect($a)->toBe($b);
});
it('applies the same rules to .svelte files', function () {
it('applies the same rules to .svelte files', function (): void {
$a = ContentHash::ofContent('a.svelte', "<script>\n// comment\nlet foo = 1;\n</script>");
$b = ContentHash::ofContent('a.svelte', '<script> let foo = 1; </script>');
expect($a)->toBe($b);
});
it('applies the same rules to .mjs, .cjs, and .mts files', function () {
it('applies the same rules to .mjs, .cjs, and .mts files', function (): void {
foreach (['mjs', 'cjs', 'mts'] as $ext) {
$a = ContentHash::ofContent("a.$ext", "// comment\nexport const foo = 1;");
$b = ContentHash::ofContent("a.$ext", 'export const foo = 1;');
@@ -215,29 +215,29 @@ describe('JavaScript-like files', function () {
});
});
describe('unknown extensions', function () {
it('hashes the raw content for unknown extensions', function () {
describe('unknown extensions', function (): void {
it('hashes the raw content for unknown extensions', function (): void {
$a = ContentHash::ofContent('a.txt', 'hello world');
$b = ContentHash::ofContent('a.txt', 'hello world');
expect($a)->toBe($b);
});
it('does not normalise whitespace for unknown extensions', function () {
it('does not normalise whitespace for unknown extensions', function (): void {
$a = ContentHash::ofContent('a.txt', 'hello world');
$b = ContentHash::ofContent('a.txt', 'hello world');
expect($a)->not->toBe($b);
});
it('does not strip comments for unknown extensions', function () {
it('does not strip comments for unknown extensions', function (): void {
$a = ContentHash::ofContent('a.txt', "// not a comment here\nhello");
$b = ContentHash::ofContent('a.txt', 'hello');
expect($a)->not->toBe($b);
});
it('hashes files with no extension as raw content', function () {
it('hashes files with no extension as raw content', function (): void {
$a = ContentHash::ofContent('Makefile', "all:\n\techo hi");
$b = ContentHash::ofContent('Makefile', "all:\n\techo hi");
@@ -245,14 +245,14 @@ describe('unknown extensions', function () {
});
});
describe('output format', function () {
it('returns a 32-character hex xxh128 hash', function () {
describe('output format', function (): void {
it('returns a 32-character hex xxh128 hash', function (): void {
$hash = ContentHash::ofContent('a.php', '<?php $foo = 1;');
expect($hash)->toMatch('/^[a-f0-9]{32}$/');
});
it('returns a stable hash for empty content', function () {
it('returns a stable hash for empty content', function (): void {
$a = ContentHash::ofContent('a.php', '');
$b = ContentHash::ofContent('a.php', '');
+2 -2
View File
@@ -2,7 +2,7 @@
use Pest\Plugins\Tia;
test('does not throw when an integer --random-order-seed is passed as a separate argv element', function () {
test('does not throw when an integer --random-order-seed is passed as a separate argv element', function (): void {
// Mirrors the parallel worker argv (see bin/worker.php), where
// `--random-order-seed` and its value arrive as separate items and the
// seed value is an int rather than a string. Regression test for the
@@ -13,7 +13,7 @@ test('does not throw when an integer --random-order-seed is passed as a separate
expect(Tia::isEnabledForRun($arguments))->toBeFalse();
});
test('still detects --tia when an integer argument is present', function () {
test('still detects --tia when an integer argument is present', function (): void {
$arguments = ['--tia', '--random-order-seed', 1782350398];
expect(Tia::isEnabledForRun($arguments))->toBeTrue();
@@ -0,0 +1,121 @@
<?php
use Pest\Plugins\Tia\Lockfiles\PackageLock;
$lock = (fn (array $packages, ?string $name = null): string => json_encode([
'name' => $name ?? 'app',
'lockfileVersion' => 3,
'packages' => $packages,
]));
it('applies only to package-lock.json', function (): void {
$handler = new PackageLock;
expect($handler->applies('package-lock.json'))->toBeTrue()
->and($handler->applies('pnpm-lock.yaml'))->toBeFalse()
->and($handler->applies('yarn.lock'))->toBeFalse();
});
it('returns null for contents that are not an npm lockfile', function (): void {
$handler = new PackageLock;
expect($handler->fingerprint('not json'))->toBeNull()
->and($handler->fingerprint('{"lockfileVersion":1}'))->toBeNull();
});
it('is stable when the directory-derived top-level name changes', function () use ($lock): void {
$handler = new PackageLock;
$packages = ['node_modules/react' => ['version' => '19.0.0']];
expect($handler->fingerprint($lock($packages, 'app-a')))
->toBe($handler->fingerprint($lock($packages, 'app-b')));
});
it('ignores platform-specific native binaries added or dropped per OS', function () use ($lock): void {
$handler = new PackageLock;
$mac = $lock([
'node_modules/react' => ['version' => '19.0.0'],
'node_modules/@rollup/rollup-darwin-arm64' => [
'version' => '4.9.5', 'os' => ['darwin'], 'cpu' => ['arm64'], 'optional' => true,
],
], 'app');
$linux = $lock([
'node_modules/react' => ['version' => '19.0.0'],
'node_modules/@rollup/rollup-linux-x64-gnu' => [
'version' => '4.52.1', 'os' => ['linux'], 'cpu' => ['x64'], 'optional' => true,
],
], 'app');
expect($handler->fingerprint($mac))->toBe($handler->fingerprint($linux));
});
it('ignores libc-constrained variants', function () use ($lock): void {
$handler = new PackageLock;
$gnu = $lock([
'node_modules/lightningcss-linux-x64-gnu' => [
'version' => '1.32.0', 'os' => ['linux'], 'cpu' => ['x64'], 'libc' => ['glibc'], 'optional' => true,
],
]);
expect($handler->fingerprint($gnu))->toBe($handler->fingerprint($lock([])));
});
it('ignores runtime deps bundled beneath a platform-specific package', function () use ($lock): void {
$handler = new PackageLock;
$withoutBundled = $lock([
'node_modules/react' => ['version' => '19.0.0'],
'node_modules/@rolldown/binding-wasm32-wasi' => [
'version' => '1.0.0', 'cpu' => ['wasm32'], 'optional' => true,
],
]);
$withBundled = $lock([
'node_modules/react' => ['version' => '19.0.0'],
'node_modules/@rolldown/binding-wasm32-wasi' => [
'version' => '1.0.0', 'cpu' => ['wasm32'], 'optional' => true,
],
'node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/core' => ['version' => '1.4.0'],
]);
expect($handler->fingerprint($withoutBundled))->toBe($handler->fingerprint($withBundled));
});
it('detects a real dependency version change', function () use ($lock): void {
$handler = new PackageLock;
$before = $lock(['node_modules/react' => ['version' => '19.0.0']]);
$after = $lock(['node_modules/react' => ['version' => '19.1.0']]);
expect($handler->fingerprint($before))->not->toBe($handler->fingerprint($after));
});
it('detects an added or removed non-platform dependency', function () use ($lock): void {
$handler = new PackageLock;
$before = $lock(['node_modules/react' => ['version' => '19.0.0']]);
$after = $lock([
'node_modules/react' => ['version' => '19.0.0'],
'node_modules/vue' => ['version' => '3.5.0'],
]);
expect($handler->fingerprint($before))->not->toBe($handler->fingerprint($after));
});
it('is independent of package ordering', function () use ($lock): void {
$handler = new PackageLock;
$a = $lock([
'node_modules/a' => ['version' => '1.0.0'],
'node_modules/b' => ['version' => '2.0.0'],
]);
$b = $lock([
'node_modules/b' => ['version' => '2.0.0'],
'node_modules/a' => ['version' => '1.0.0'],
]);
expect($handler->fingerprint($a))->toBe($handler->fingerprint($b));
});
+7 -7
View File
@@ -259,34 +259,34 @@ function tiaAliasResults(): array
return $cache = ['roots' => $roots, 'aliases' => $aliases];
}
beforeEach(function () {
beforeEach(function (): void {
if ((new ExecutableFinder)->find('node') === null) {
$this->markTestSkipped('node is not available.');
}
});
it('strips JSONC down to something JSON.parse accepts', function (string $name) {
it('strips JSONC down to something JSON.parse accepts', function (string $name): void {
$result = tiaStripResults()[$name];
[, $expected] = tiaStripFixtures()[$name];
expect($result['ok'])->toBeTrue(
"[{$name}] did not parse after stripping: ".($result['error'] ?? 'unknown').PHP_EOL.
'stripped: '.$result['stripped'],
);
expect($result['parsed'])->toEqual($expected);
)
->and($result['parsed'])->toEqual($expected);
})->with(array_keys(tiaStripFixtures()));
it('never touches comment-looking sequences inside string values', function () {
it('never touches comment-looking sequences inside string values', function (): void {
expect(tiaStripResults()['url-in-string']['stripped'])->toContain('https://example.com//x')
->and(tiaStripResults()['glob-in-string']['stripped'])->toContain('resources/js/**/*.ts')
->and(tiaStripResults()['block-both-in-string']['stripped'])->toContain('x/*y*/z');
});
it('removes the comment body entirely', function () {
it('removes the comment body entirely', function (): void {
expect(tiaStripResults()['block-secret']['stripped'])->not->toContain('SECRET');
});
it('builds the expected alias map from a tsconfig', function (string $name) {
it('builds the expected alias map from a tsconfig', function (string $name): void {
$results = tiaAliasResults();
[, $expectedRelative] = tiaAliasFixtures()[$name];