@atomicsmash/init-testing 1.0.0 → 1.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
2
3
  import { readFile, writeFile, readdir, appendFile, mkdir, } from "node:fs/promises";
3
4
  import { resolve as pathResolve, relative as pathRelative } from "node:path";
4
5
  import yargs from "yargs";
@@ -19,6 +20,7 @@ const packageManager = new PackageManager(await import(`${process.cwd()}/package
19
20
  console.log({ error });
20
21
  throw new Error("Unable to find package-lock.json in your cwd. Make sure you're running this command in the right folder.");
21
22
  }));
23
+ const hasRootTSConfig = existsSync(`${process.cwd()}/tsconfig.json`);
22
24
  const argv = await yargs(hideBin(process.argv))
23
25
  .options({
24
26
  "base-url": {
@@ -68,6 +70,12 @@ for (const dirent of copyFiles) {
68
70
  .then(async (data) => {
69
71
  for (const [search, replace] of [
70
72
  ["%%BASE_URL%%", argv.baseUrl],
73
+ [
74
+ "%%TS_CONFIG_LOCATION%%",
75
+ hasRootTSConfig
76
+ ? "../tsconfig.json"
77
+ : "@atomicsmash/coding-standards/typescript/base",
78
+ ],
71
79
  ]) {
72
80
  data = data.replace(search, replace);
73
81
  }
@@ -111,12 +119,27 @@ await Promise.all([
111
119
  type: "dev",
112
120
  });
113
121
  },
114
- ]).then((results) => {
122
+ !hasRootTSConfig
123
+ ? packageManager.ensurePackageIsInstalled("typescript", {
124
+ packageConstraint: "^5.4.0",
125
+ type: "dev",
126
+ })
127
+ : false,
128
+ ])
129
+ .then((results) => {
115
130
  if (results.some((result) => {
116
131
  return result.status === "fulfilled" && result.value === true;
117
132
  })) {
118
133
  packageManager.runCommands();
119
134
  }
135
+ return results[1].status === "fulfilled" && results[1].value === true;
136
+ })
137
+ .then((shouldInstallPlaywright) => {
138
+ if (shouldInstallPlaywright) {
139
+ // Run Playwright installer after package install
140
+ packageManager.commands.basic.push("npx playwright install");
141
+ packageManager.runCommands();
142
+ }
120
143
  }),
121
144
  Promise.allSettled(fileCopies).then((results) => {
122
145
  results.forEach((result) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/init-testing",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.0-beta.1",
5
5
  "description": "Allow us to easily add automated testing setup to any npm setup.",
6
6
  "keywords": [
7
7
  "atomic",
@@ -3,7 +3,7 @@ import {
3
3
  checkPrivilegedPages,
4
4
  checkForLoremIpsum,
5
5
  } from "@atomicsmash/test-utils";
6
- import { test, lighthouseTest, pagesToTest } from "../playwright-utils";
6
+ import { test, lighthouseTest, pagesToTest } from "../playwright-utils.mjs";
7
7
 
8
8
  test(
9
9
  "privileged pages of the site to ensure non-logged in users can't access them",
@@ -0,0 +1,42 @@
1
+ import type {
2
+ AuthenticatePageFunction,
3
+ PageList,
4
+ } from "@atomicsmash/test-utils";
5
+ import type { Page } from "@playwright/test";
6
+ import { getLighthouseTest } from "@atomicsmash/test-utils";
7
+ import { test as base } from "@playwright/test";
8
+ import { testData } from "./fixtures/testData.js";
9
+
10
+ /**
11
+ * Fixtures
12
+ */
13
+ const logInUser: AuthenticatePageFunction = async function ({ page }, use) {
14
+ // Do any actions here to log a user in so you can access logged in areas of the site.
15
+ // This is useful for testing my account pages, etc.
16
+ await use(page);
17
+ };
18
+
19
+ type CustomFixtures = {
20
+ testData: typeof testData;
21
+ authenticatedPage: Page;
22
+ };
23
+
24
+ export const test = base.extend<CustomFixtures>({
25
+ testData: async (
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ { page },
28
+ use,
29
+ ) => {
30
+ // Use the fixture value in the test.
31
+ await use(testData);
32
+ },
33
+ authenticatedPage: [logInUser, { scope: "test" }],
34
+ });
35
+
36
+ export const lighthouseTest = getLighthouseTest(logInUser);
37
+ export const { expect } = test; // re-export expect to cleanup imports in tests
38
+ export { checkAccessibility } from "@atomicsmash/test-utils";
39
+
40
+ export const pagesToTest = [
41
+ // hover over PageList to see the format required for each page
42
+ ] satisfies PageList;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/tsconfig",
3
- "include": ["./**/*.ts"],
4
- "extends": ["../tsconfig.json"]
3
+ "include": ["./**/*.ts", "./**/*.mts", "./**/*.cts"],
4
+ "extends": ["%%TS_CONFIG_LOCATION%%"]
5
5
  }
@@ -1,42 +0,0 @@
1
- import type {
2
- AuthenticatePageFunction,
3
- PageList,
4
- } from '@atomicsmash/test-utils'
5
- import type { Page } from '@playwright/test'
6
- import { getLighthouseTest } from '@atomicsmash/test-utils'
7
- import { test as base } from '@playwright/test'
8
- import { testData } from './fixtures/testData.js'
9
-
10
- /**
11
- * Fixtures
12
- */
13
- const logInUser: AuthenticatePageFunction = async function ({ page }, use) {
14
- // Do any actions here to log a user in so you can access logged in areas of the site.
15
- // This is useful for testing my account pages, etc.
16
- await use(page)
17
- }
18
-
19
- type CustomFixtures = {
20
- testData: typeof testData
21
- authenticatedPage: Page
22
- }
23
-
24
- export const test = base.extend<CustomFixtures>({
25
- testData: async (
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
- { page },
28
- use
29
- ) => {
30
- // Use the fixture value in the test.
31
- await use(testData)
32
- },
33
- authenticatedPage: [logInUser, { scope: 'test' }],
34
- })
35
-
36
- export const lighthouseTest = getLighthouseTest(logInUser)
37
- export const { expect } = test // re-export expect to cleanup imports in tests
38
- export { checkAccessibility } from '@atomicsmash/test-utils'
39
-
40
- export const pagesToTest: PageList = [
41
- // hover over PageList to see the format required for each page
42
- ]