Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boilerplate/skeleton/extension/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:unit:filter": "phpunit -c tests/phpunit.unit.xml --filter",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:integration:filter": "phpunit -c tests/phpunit.integration.xml --filter",
"test:setup": "@php tests/integration/setup.php",
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:unit:filter": "Runs unit tests whose name matches: composer test:unit:filter -- ClassName",
"test:integration": "Runs all integration tests.",
"test:integration:filter": "Runs integration tests whose name matches: composer test:integration:filter -- ClassName",
"test:setup": "Sets up a database for use with integration tests. Execute this only once.",
"analyse:phpstan": "Run static analysis"
},
Expand Down
4 changes: 4 additions & 0 deletions src/steps/gen-ext-scaffolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,15 @@ function moduleNameToDef(name: ExtensionModules): Module<ExtensionModules> {
'autoload-dev.psr-4.${params.packageNamespace}\\Tests\\',
'scripts.test',
'scripts.test:unit',
'scripts.test:unit:filter',
'scripts.test:integration',
'scripts.test:integration:filter',
'scripts.test:setup',
'scripts-descriptions.test',
'scripts-descriptions.test:unit',
'scripts-descriptions.test:unit:filter',
'scripts-descriptions.test:integration',
'scripts-descriptions.test:integration:filter',
'scripts-descriptions.test:setup',
'require-dev.flarum/testing',
],
Expand Down
21 changes: 21 additions & 0 deletions test/steps/init/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,25 @@ describe('Test extension skeleton step', function () {
expect(getExtFileContents(fs, '.github/workflows/frontend.yml').includes('my/prod/branch')).toBe(true);
expect(await getEnabledModules(fs)).toStrictEqual(buildModules([]));
});

test('Adds scripts to run only the tests whose name matches', async function () {
const { fs } = await runStep(initStep, {}, { usePrompts: false, initialParams: vars });

const composerJson = JSON.parse(getExtFileContents(fs, 'composer.json'));

expect(composerJson.scripts['test:unit:filter']).toBe('phpunit -c tests/phpunit.unit.xml --filter');
expect(composerJson.scripts['test:integration:filter']).toBe('phpunit -c tests/phpunit.integration.xml --filter');
expect(composerJson['scripts-descriptions']['test:unit:filter']).toBeDefined();
expect(composerJson['scripts-descriptions']['test:integration:filter']).toBeDefined();
});

test('Leaves out every test script without backend testing', async function () {
const { fs } = await runStep(initStep, {}, { usePrompts: false, initialParams: { ...vars, 'modules.backendTesting': false } });

const composerJson = JSON.parse(getExtFileContents(fs, 'composer.json'));
const testScripts = (scripts: Record<string, unknown> = {}) => Object.keys(scripts).filter((name) => name.startsWith('test'));

expect(testScripts(composerJson.scripts)).toStrictEqual([]);
expect(testScripts(composerJson['scripts-descriptions'])).toStrictEqual([]);
});
});
Loading