-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a couple of issues with config files in websnacks projects. First, config files are no longer required and the dev and build commands will no longer error out if a websnacks.ts/js file doesn't exist. Second, all optional user config params are now actually optional - before some parameters were assumed to exist and would error out if not present (e.g. the "watch" parameter). Finally, e2e tests were added to prevent regressions on these issues and test helpers were extracted to a separate file.
- Loading branch information
1 parent
98f761a
commit 5520bb3
Showing
5 changed files
with
410 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { promises as fs } from "fs"; | ||
import * as path from "path"; | ||
|
||
import { runCommand, WEBSNACKS_BIN_PATH, WEBSNACKS_REPO_ROOT, withTempDir } from "../helpers/e2e"; | ||
import { testSuite } from "../lib"; | ||
|
||
testSuite("build command", ({ test }) => { | ||
test("runs without throwing error", async () => { | ||
await withTempDir(async (tempDirPath) => { | ||
await fs.writeFile( | ||
path.join(tempDirPath, "tsconfig.json"), | ||
JSON.stringify({ | ||
compilerOptions: { | ||
esModuleInterop: true, | ||
module: "CommonJS", | ||
moduleResolution: "node", | ||
jsx: "react", | ||
jsxFactory: "createElement", | ||
target: "ES2018", | ||
lib: ["ES2018"], | ||
strict: true, | ||
noUnusedLocals: true, | ||
noUnusedParameters: true, | ||
noImplicitReturns: true, | ||
noFallthroughCasesInSwitch: true, | ||
}, | ||
include: ["components/**/*", "pages/**/*"], | ||
}), | ||
{ | ||
encoding: "utf8", | ||
} | ||
); | ||
await fs.writeFile( | ||
path.join(tempDirPath, "websnacks.ts"), | ||
` | ||
import { Config } from "${WEBSNACKS_REPO_ROOT}"; | ||
const config: Config = { | ||
watch: [], | ||
}; | ||
export = config; | ||
`, | ||
{ | ||
encoding: "utf8", | ||
} | ||
); | ||
const pagesPath = path.join(tempDirPath, "pages"); | ||
await fs.mkdir(pagesPath); | ||
await fs.writeFile( | ||
path.join(pagesPath, "index.tsx"), | ||
` | ||
import { createElement } from "${WEBSNACKS_REPO_ROOT}"; | ||
export const page = () => <html />; | ||
`, | ||
{ | ||
encoding: "utf8", | ||
} | ||
); | ||
const cmd = runCommand( | ||
"node", | ||
[WEBSNACKS_BIN_PATH, "-r", "ts-node/register", "build"], | ||
{ | ||
cwd: tempDirPath, | ||
} | ||
); | ||
await cmd.complete; | ||
}); | ||
}); | ||
|
||
test("works without config file", async () => { | ||
await withTempDir(async (tempDirPath) => { | ||
await fs.writeFile( | ||
path.join(tempDirPath, "tsconfig.json"), | ||
JSON.stringify({ | ||
compilerOptions: { | ||
esModuleInterop: true, | ||
module: "CommonJS", | ||
moduleResolution: "node", | ||
jsx: "react", | ||
jsxFactory: "createElement", | ||
target: "ES2018", | ||
lib: ["ES2018"], | ||
strict: true, | ||
noUnusedLocals: true, | ||
noUnusedParameters: true, | ||
noImplicitReturns: true, | ||
noFallthroughCasesInSwitch: true, | ||
}, | ||
include: ["components/**/*", "pages/**/*"], | ||
}), | ||
{ | ||
encoding: "utf8", | ||
} | ||
); | ||
const pagesPath = path.join(tempDirPath, "pages"); | ||
await fs.mkdir(pagesPath); | ||
await fs.writeFile( | ||
path.join(pagesPath, "index.tsx"), | ||
` | ||
import { createElement } from "${WEBSNACKS_REPO_ROOT}"; | ||
export const page = () => <html />; | ||
`, | ||
{ | ||
encoding: "utf8", | ||
} | ||
); | ||
const cmd = runCommand( | ||
"node", | ||
[WEBSNACKS_BIN_PATH, "-r", "ts-node/register", "build"], | ||
{ | ||
cwd: tempDirPath, | ||
} | ||
); | ||
await cmd.complete; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.