Skip to content

Commit

Permalink
Update custom build tests and update the runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
shammowla committed Jan 29, 2024
1 parent 0556160 commit 06d8b3b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 48 deletions.
62 changes: 37 additions & 25 deletions scripts/helpers/runFunctionalTests.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
#!/usr/bin/env node

const fs = require("fs");
const glob = require("glob");
const createTestCafe = require("testcafe");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");

const argv = yargs(hideBin(process.argv)).option("exclude", {
type: "array",
default: []
}).argv;

glob("test/functional/specs/**/*.js", (err, files) => {
if (err) {
console.error(err);
process.exit(1);

fs.readFile("dist/alloy.js", "utf8", (readFileErr, data) => {
if (readFileErr) {
console.error(`readFile error: ${readFileErr}`);
return;
}

const testFiles = files.filter(file => {
const shouldExclude = argv.exclude.some(excludedDir =>
file.includes(excludedDir)
);
return !shouldExclude;
});
glob("test/functional/specs/**/*.js", (globErr, files) => {
if (globErr) {
console.error(globErr);
process.exit(1);
}

let componentNames = files.map(file => file.split("/")[3]);
componentNames = [...new Set(componentNames)]; // remove duplicates

const testFiles = [];
const excludedComponents = [];

componentNames.forEach(name => {
if (data.includes(`alloy_${name}`)) {
testFiles.push(files.find(file => file.split("/")[3] === name));
} else {
excludedComponents.push(name);
}
});

if (excludedComponents.length > 0) {
console.log(`Excluding components: ${excludedComponents.join(", ")}`);
}

createTestCafe().then(testcafe => {
const runner = testcafe.createRunner();
runner
.src(testFiles)
.browsers("chrome")
.run()
.then(() => testcafe.close());
createTestCafe().then(testcafe => {
const runner = testcafe.createRunner();
runner
.src(testFiles)
.browsers("chrome")
.run()
.then(() => testcafe.close());
});
});
});
13 changes: 6 additions & 7 deletions test/functional/specs/CustomBuild/buildCompletesWithoutErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const { exec } = require("child_process");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const assert = require("chai").assert;

// eslint-disable-next-line no-unused-vars
test("Check if build completes without errors", async t => {
exec("npm run build:custom", (error, stdout, stderr) => {
assert.isNull(error);
assert.isEmpty(stderr);
});
test("Check if build completes without errors", async () => {
const { error, stderr } = await exec("npm run build:custom");
assert.isNull(error);
assert.isEmpty(stderr);
});
14 changes: 8 additions & 6 deletions test/functional/specs/CustomBuild/buildFailsWhenExpected.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const { exec } = require("child_process");

const util = require("util");
const exec = util.promisify(require("child_process").exec);

test("Check if build fails when expected", async () => {
exec("npm run build:custom -- --exclude nonExistingComponent", error => {
if (!error) {
console.error("Expected error but none was thrown");
}
});
try {
await exec("npm run build:custom -- --exclude nonExistingComponent");
} catch (error) {
console.error("Expected error but none was thrown");
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const { exec } = require("child_process");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const assert = require("chai").assert;

test("Check if build works with different configurations", async () => {
exec(
"npm run build:custom -- --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN",
(error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
assert.isEmpty(stderr);
}
const { error, stderr } = await exec(
"npm run build:custom -- --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN"
);
assert.isNull(error);
assert.isEmpty(stderr);
});

0 comments on commit 06d8b3b

Please sign in to comment.