|
1 | 1 | "use strict";
|
2 | 2 | const path = require("path");
|
| 3 | +const chalk = require("chalk"); |
3 | 4 | const assert = require("yeoman-assert");
|
4 | 5 | const helpers = require("yeoman-test");
|
| 6 | +const validators = require("../generators/app/validator"); |
5 | 7 |
|
6 |
| -describe("generator-biojs-webcomponents:app", () => { |
| 8 | +describe("generator-biojs-webcomponents:app - Make a new Web Component", () => { |
7 | 9 | beforeAll(() => {
|
8 | 10 | return helpers.run(path.join(__dirname, "../generators/app")).withPrompts({
|
9 | 11 | upgradeOrMake: "Make a new Web Component",
|
@@ -62,4 +64,117 @@ describe("generator-biojs-webcomponents:app", () => {
|
62 | 64 | ]);
|
63 | 65 | });
|
64 | 66 | });
|
| 67 | + it("throws an error if user enters an empty string as toolNameHuman", async () => { |
| 68 | + assert.equal( |
| 69 | + await validators.toolNameHuman(""), |
| 70 | + chalk.red("This is a mandatory field, please answer.") |
| 71 | + ); |
| 72 | + }); |
| 73 | + it("throws an error if user enters an empty string as toolNameComputer", async () => { |
| 74 | + assert.equal( |
| 75 | + await validators.toolNameComputer(""), |
| 76 | + chalk.red("This is a mandatory field, please answer.") |
| 77 | + ); |
| 78 | + }); |
| 79 | +}); |
| 80 | + |
| 81 | +describe("generator-biojs-webcomponents:app - Upgrade an existing component by importing build file locally", () => { |
| 82 | + it("imports the build file", async () => { |
| 83 | + await validators |
| 84 | + .importBuildFileLocally( |
| 85 | + path.join(__dirname, "../generators/app/validator.js") |
| 86 | + ) |
| 87 | + .then(() => { |
| 88 | + assert.file(["component-dist/validator.js"]); |
| 89 | + }); |
| 90 | + }); |
| 91 | + it("only pastes the build file", async () => { |
| 92 | + // This will work as the directory component-dist already exists because of the above test |
| 93 | + await validators |
| 94 | + .copyBuildFileLocally(path.join(__dirname, "../LICENSE")) |
| 95 | + .then(() => { |
| 96 | + assert.file(["component-dist/LICENSE"]); |
| 97 | + }); |
| 98 | + }); |
| 99 | + it("skips the current question if user enters skip", async () => { |
| 100 | + assert.equal(await validators.importBuildFileLocally("skip"), true); |
| 101 | + }); |
| 102 | + it("throws an error if user enters an empty string as path of build file", async () => { |
| 103 | + assert.equal( |
| 104 | + await validators.importBuildFileFromNPM(""), |
| 105 | + chalk.red("This is a mandatory field, please answer.") |
| 106 | + ); |
| 107 | + }); |
| 108 | + it("throws an error if user enters an empty string as path of build file to be copied", async () => { |
| 109 | + assert.equal( |
| 110 | + await validators.copyBuildFileLocally(""), |
| 111 | + chalk.red("This is a mandatory field, please answer.") |
| 112 | + ); |
| 113 | + }); |
| 114 | +}); |
| 115 | + |
| 116 | +describe("generator-biojs-webcomponents:app - Upgrade an existing component by importing build file using npm", () => { |
| 117 | + it("works successfully if the package name and version entered is correct", async () => { |
| 118 | + assert.equal( |
| 119 | + await validators.version("fkdk", { packageName: "node" }), |
| 120 | + chalk.red( |
| 121 | + "Sorry, the version - " + |
| 122 | + chalk.red.bold("fkdk") + |
| 123 | + " doesn't exist. Please enter again. Enter " + |
| 124 | + chalk.cyan("latest") + |
| 125 | + " if you want to import the latest version." |
| 126 | + ) |
| 127 | + ); |
| 128 | + }); |
| 129 | + it("skips the current question if user enters skip", async () => { |
| 130 | + assert.equal(await validators.importBuildFileFromNPM("skip"), true); |
| 131 | + }); |
| 132 | + it("downloads the file if URL entered is correct", async () => { |
| 133 | + // This will work as the directory component-dist is already created above |
| 134 | + await validators |
| 135 | + .copyBuildFileFromNPM( |
| 136 | + "https://cdn.jsdelivr.net/npm/[email protected]/build/protvista.min.gz.js" |
| 137 | + ) |
| 138 | + .then(() => { |
| 139 | + assert.file(["component-dist/protvista.min.gz.js"]); |
| 140 | + }); |
| 141 | + }); |
| 142 | + it("throws an error if an npm package doesn't exist", async () => { |
| 143 | + assert.equal( |
| 144 | + await validators.packageName("cbaxyz"), |
| 145 | + chalk.red( |
| 146 | + "There's no package on npm with the name " + |
| 147 | + chalk.red.bold("cbaxyz") + |
| 148 | + ". Please note that the package name is case sensitive." |
| 149 | + ) |
| 150 | + ); |
| 151 | + }); |
| 152 | + it("throws an error if an user enters an empty string as the package name", async () => { |
| 153 | + assert.equal( |
| 154 | + await validators.packageName(""), |
| 155 | + chalk.red("This is a mandatory field, please answer.") |
| 156 | + ); |
| 157 | + }); |
| 158 | + it("throws an error if version entered is empty", async () => { |
| 159 | + assert.equal( |
| 160 | + await validators.version("", { packageName: "node" }), |
| 161 | + chalk.red( |
| 162 | + "This is a mandatory field, please answer. Enter " + |
| 163 | + chalk.cyan("latest") + |
| 164 | + " if you want to import the latest version." |
| 165 | + ) |
| 166 | + ); |
| 167 | + }); |
| 168 | + it("throws an error if downloadURL entered is empty", async () => { |
| 169 | + assert.equal( |
| 170 | + await validators.importBuildFileFromNPM(""), |
| 171 | + chalk.red("This is a mandatory field, please answer.") |
| 172 | + ); |
| 173 | + }); |
| 174 | + it("throws an error if downloadURL for build file to copied entered is empty", async () => { |
| 175 | + assert.equal( |
| 176 | + await validators.copyBuildFileFromNPM(""), |
| 177 | + chalk.red("This is a mandatory field, please answer.") |
| 178 | + ); |
| 179 | + }); |
65 | 180 | });
|
0 commit comments