Skip to content

Commit

Permalink
chore/refactor test cases for better sync vs async test running (#1193)
Browse files Browse the repository at this point in the history
* refactor test cases for better sync vs async test running

* re-enable excluded SSR specs

* patch stopCommand refactor

* upgrade gallinago to latest version
  • Loading branch information
thescientist13 committed Dec 31, 2023
1 parent 098cdee commit 8af3519
Show file tree
Hide file tree
Showing 127 changed files with 435 additions and 436 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "cross-env __GWD_ROLLUP_MODE__=strict node . build",
"serve": "node . serve",
"develop": "node . develop",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 c8 mocha --exclude \"./packages/**/test/cases/exp-*/**\" --exclude \"./packages/cli/test/cases/serve.default.ssr/**\" --exclude \"./packages/cli/test/cases/*.default.ssr-static-export/**\" \"./packages/**/**/*.spec.js\"",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 c8 mocha --exclude \"./packages/**/test/cases/exp-*/**\" \"./packages/**/**/*.spec.js\"",
"test:exp": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --experimental-loader $(pwd)/test/test-loader.js ./node_modules/mocha/bin/mocha \"./packages/**/**/*.spec.js\"",
"test:exp:win": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --experimental-loader file:\\\\%cd%\\test\\test-loader.js ./node_modules/mocha/bin/mocha --exclude \"./packages/init/test/cases/**\" \"./packages/**/**/*.spec.js\"",
"test:tdd": "yarn test --watch",
Expand All @@ -43,7 +43,7 @@
"eslint": "^8.51.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-no-only-tests": "^2.6.0",
"gallinago": "^0.7.0",
"gallinago": "^0.8.0",
"glob-promise": "^3.4.0",
"jsdom": "^16.5.0",
"lerna": "^3.16.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('Build Greenwood With: ', function() {
});

describe(LABEL, function() {
before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

runSmokeTest(['public', 'index'], LABEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value for devServer.extensions', function() {
it('should throw an error that provided extensions is not valid', async function() {
it('should throw an error that provided extensions is not valid', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: provided extensions is not an array. Please provide an array like [\'.txt\', \'.foo\']');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ describe('Build Greenwood With: ', function() {
});

describe('Custom Configuration with a bad value for devServer.hud', function() {
it('should throw an error that provided extensions is not valid', async function() {
it('should throw an error that provided extensions is not valid', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: greenwood.config.js devServer hud options must be a boolean. Passed value was: 1234');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value for optimization', function() {
it('should throw an error that provided optimization is not valid', async function() {
it('should throw an error that provided optimization is not valid', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: provided optimization "loremipsum" is not supported. Please use one of: default, none, static, inline.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value for pagesDirectory', function() {
it('should throw an error that pagesDirectory must be a string', async function() {
it('should throw an error that pagesDirectory must be a string', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: provided pagesDirectory "[object Object]" is not supported. Please make sure to pass something like \'docs/\'');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value for Prerender', function() {
it('should throw an error that prerender must be a boolean', async function() {
it('should throw an error that prerender must be a boolean', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: greenwood.config.js prerender must be a boolean; true or false. Passed value was typeof: object');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value for templatesDirectory', function() {
it('should throw an error that templatesDirectory must be a string', async function() {
it('should throw an error that templatesDirectory must be a string', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: provided templatesDirectory "[object Object]" is not supported. Please make sure to pass something like \'layouts/\'');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value (absolute path) for Workspace', function() {
it('should throw an error that workspace path must exist', async function() {
it('should throw an error that workspace path must exist', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('greenwood.config.js workspace doesn\'t exist!');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe('Custom Configuration with a bad value for Workspace', function() {
it('should throw an error that workspace path must be a URL', async function() {
it('should throw an error that workspace path must be a URL', function() {
try {
await runner.setup(outputPath);
await runner.runCommand(cliPath, 'build');
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
} catch (err) {
expect(err).to.contain('Error: greenwood.config.js workspace must be an instance of URL');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

describe('Frontmatter should be interpolated in the correct places', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ describe('Build Greenwood With: ', function() {
});

describe(LABEL, function() {
before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

runSmokeTest(['public', 'index'], LABEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
Expand All @@ -42,9 +42,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

describe('Custom Markdown Presets', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ describe('Build Greenwood With: ', function() {
`${outputPath}/node_modules/prismjs/themes/`
);

await runner.setup(outputPath, [
runner.setup(outputPath, [
...getSetupFiles(outputPath),
...prismCss
]);
await runner.runCommand(cliPath, 'build');
runner.runCommand(cliPath, 'build');
});

describe('Output for JavaScript / CSS tags and files', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
Expand All @@ -49,9 +49,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

describe('Output for JavaScript / CSS tags and files', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

describe('Output for JavaScript / CSS tags and files', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
Expand All @@ -46,9 +46,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

describe('Cumulative output based on all override settings', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
Expand All @@ -45,9 +45,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

describe('JavaScript <script> tag and file static optimization', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

runSmokeTest(['public', 'index'], LABEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describe('Build Greenwood With: ', function() {

describe(LABEL, function() {

before(async function() {
await runner.setup(outputPath, getSetupFiles(outputPath));
await runner.runCommand(cliPath, 'build');
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});

runSmokeTest(['public', 'index'], LABEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(async function() {
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
Expand All @@ -53,11 +53,11 @@ describe('Build Greenwood With: ', function() {
`${outputPath}/node_modules/@greenwood/cli/src/lib`
);

await runner.setup(outputPath, [
runner.setup(outputPath, [
...getSetupFiles(outputPath),
...greenwoodRouterLibs
]);
await runner.runCommand(cliPath, 'build');
runner.runCommand(cliPath, 'build');
});

runSmokeTest(['public', 'index'], LABEL);
Expand Down
Loading

0 comments on commit 8af3519

Please sign in to comment.