@stencil/core 2.17.0 → 2.17.2

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.
Files changed (50) hide show
  1. package/cli/config-flags.d.ts +110 -0
  2. package/cli/index.cjs +675 -253
  3. package/cli/index.d.ts +3 -2
  4. package/cli/index.js +675 -253
  5. package/cli/package.json +1 -1
  6. package/compiler/package.json +1 -1
  7. package/compiler/stencil.js +676 -226
  8. package/compiler/stencil.min.js +2 -2
  9. package/dependencies.json +1 -1
  10. package/dev-server/client/index.js +1 -1
  11. package/dev-server/client/package.json +1 -1
  12. package/dev-server/connector.html +2 -2
  13. package/dev-server/index.js +1 -1
  14. package/dev-server/package.json +1 -1
  15. package/dev-server/server-process.js +2 -2
  16. package/internal/app-data/package.json +1 -1
  17. package/internal/client/css-shim.js +1 -1
  18. package/internal/client/dom.js +1 -1
  19. package/internal/client/index.js +11 -6
  20. package/internal/client/package.json +1 -1
  21. package/internal/client/patch-browser.js +1 -1
  22. package/internal/client/patch-esm.js +1 -1
  23. package/internal/client/shadow-css.js +1 -1
  24. package/internal/hydrate/index.js +2 -2
  25. package/internal/hydrate/package.json +1 -1
  26. package/internal/package.json +1 -1
  27. package/internal/stencil-private.d.ts +14 -4
  28. package/internal/stencil-public-compiler.d.ts +67 -48
  29. package/internal/testing/index.js +1 -1
  30. package/internal/testing/package.json +1 -1
  31. package/mock-doc/index.cjs +41 -3
  32. package/mock-doc/index.d.ts +15 -0
  33. package/mock-doc/index.js +41 -3
  34. package/mock-doc/package.json +1 -1
  35. package/package.json +2 -1
  36. package/screenshot/package.json +1 -1
  37. package/sys/node/index.js +4 -4
  38. package/sys/node/package.json +1 -1
  39. package/sys/node/worker.js +1 -1
  40. package/testing/index.d.ts +1 -1
  41. package/testing/index.js +71 -40
  42. package/testing/jest/jest-config.d.ts +1 -1
  43. package/testing/jest/jest-runner.d.ts +3 -2
  44. package/testing/jest/jest-screenshot.d.ts +1 -1
  45. package/testing/mocks.d.ts +28 -2
  46. package/testing/package.json +1 -1
  47. package/testing/puppeteer/puppeteer-browser.d.ts +2 -2
  48. package/testing/test/testing-utils.spec.d.ts +1 -0
  49. package/testing/testing-utils.d.ts +74 -2
  50. package/testing/testing.d.ts +2 -2
package/testing/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil Testing v2.17.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil Testing v2.17.2 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  function _lazyRequire(e) {
5
5
  return new Proxy({}, {
@@ -449,38 +449,40 @@ function versionIncluded(e) {
449
449
  return matchesRange(e);
450
450
  }
451
451
 
452
- function mockConfig(e) {
452
+ function mockConfig(e = {}) {
453
453
  const t = path__default.default.resolve("/");
454
- return e || (e = createTestingSystem()), e.getCurrentDirectory = () => t, {
454
+ let {sys: r} = e;
455
+ return r || (r = createTestingSystem()), r.getCurrentDirectory = () => t, {
455
456
  _isTesting: !0,
456
- namespace: "Testing",
457
- rootDir: t,
458
- globalScript: null,
459
- devMode: !0,
460
- enableCache: !1,
461
457
  buildAppCore: !1,
462
458
  buildDist: !0,
463
- flags: {},
464
- bundles: null,
465
- outputTargets: null,
466
459
  buildEs5: !1,
460
+ bundles: null,
461
+ devMode: !0,
462
+ enableCache: !1,
463
+ extras: {},
464
+ flags: createConfigFlags(),
465
+ globalScript: null,
467
466
  hashFileNames: !1,
468
467
  logger: new TestingLogger,
469
468
  maxConcurrentWorkers: 0,
470
469
  minifyCss: !1,
471
470
  minifyJs: !1,
472
- sys: e,
473
- testing: null,
474
- validateTypes: !1,
475
- extras: {},
471
+ namespace: "Testing",
476
472
  nodeResolve: {
477
473
  customResolveOptions: {}
478
474
  },
479
- sourceMap: !0,
475
+ outputTargets: null,
480
476
  rollupPlugins: {
481
477
  before: [],
482
478
  after: []
483
- }
479
+ },
480
+ rootDir: t,
481
+ sourceMap: !0,
482
+ sys: r,
483
+ testing: null,
484
+ validateTypes: !1,
485
+ ...e
484
486
  };
485
487
  }
486
488
 
@@ -817,6 +819,10 @@ function mockCompilerCtx(e) {
817
819
  }), t;
818
820
  }
819
821
 
822
+ function mockLogger() {
823
+ return new TestingLogger;
824
+ }
825
+
820
826
  function findRootComponent(e, t) {
821
827
  if (null != t) {
822
828
  const r = t.children, s = r.length;
@@ -2162,15 +2168,14 @@ const YELLOW = "#f39c12", RED = "#c0392b", BLUE = "#3498db", COMMON_DIR_MODULE_E
2162
2168
  let o = s.shift();
2163
2169
  o.startsWith("@") && (o += "/" + s.shift());
2164
2170
  const i = s.join("/");
2165
- if ("@stencil/core" === o) {
2166
- return ((e, t) => {
2167
- let r = (t = normalizePath(t)).split("/");
2168
- const s = r.lastIndexOf("node_modules");
2169
- return s > -1 && s < r.length - 1 && (r = r.slice(s + 1), r = r[0].startsWith("@") ? r.slice(2) : r.slice(1),
2170
- t = r.join("/")), new URL("./" + t, (e => new URL("../", e).href)(e)).href;
2171
- })(e.getCompilerExecutingPath(), i);
2172
- }
2173
- return e.getRemoteModuleUrl({
2171
+ return "@stencil/core" === o ? ((e, t) => {
2172
+ let r = (t = normalizePath(t)).split("/");
2173
+ const s = r.lastIndexOf("node_modules");
2174
+ s > -1 && s < r.length - 1 && (r = r.slice(s + 1), r = r[0].startsWith("@") ? r.slice(2) : r.slice(1),
2175
+ t = r.join("/"));
2176
+ const n = new URL("../", e).href;
2177
+ return new URL("./" + t, n).href;
2178
+ })(e.getCompilerExecutingPath(), i) : e.getRemoteModuleUrl({
2174
2179
  moduleId: o,
2175
2180
  version: t.get(o),
2176
2181
  path: i
@@ -2182,7 +2187,7 @@ const YELLOW = "#f39c12", RED = "#c0392b", BLUE = "#3498db", COMMON_DIR_MODULE_E
2182
2187
  const r = e.split("/"), s = r[r.length - 2], n = r[r.length - 1];
2183
2188
  return !("node_modules" !== s || !isCommonDirModuleFile(n));
2184
2189
  })(n) || known404Urls.has(s) || (e => knownUrlSkips.some((t => e.endsWith(t))))(s))) try {
2185
- const o = await ((e, t, r) => (console.trace(t), e && isFunction(e.fetch) ? e.fetch(t, r) : fetch(t, r)))(e, s);
2190
+ const o = await ((e, t, r) => e && isFunction(e.fetch) ? e.fetch(t, r) : fetch(t, r))(e, s);
2186
2191
  if (o) {
2187
2192
  if (o.ok) {
2188
2193
  const i = await o.clone().text();
@@ -2890,7 +2895,7 @@ const createSystem = e => {
2890
2895
  u("/");
2891
2896
  const S = {
2892
2897
  name: "in-memory",
2893
- version: "2.17.0",
2898
+ version: "2.17.2",
2894
2899
  events: i,
2895
2900
  access: async e => c(e),
2896
2901
  accessSync: c,
@@ -3262,6 +3267,14 @@ class TestingLogger {
3262
3267
  printDiagnostics(e) {}
3263
3268
  }
3264
3269
 
3270
+ const createConfigFlags = (e = {}) => ({
3271
+ task: null,
3272
+ args: [],
3273
+ knownArgs: [],
3274
+ unknownArgs: [],
3275
+ ...e
3276
+ });
3277
+
3265
3278
  class EventSpy {
3266
3279
  constructor(e) {
3267
3280
  this.eventName = e, this.events = [], this.cursor = 0, this.queuedHandler = [];
@@ -3647,8 +3660,8 @@ exports.createJestPuppeteerEnvironment = function createJestPuppeteerEnvironment
3647
3660
  }, exports.createTesting = async e => {
3648
3661
  e = function t(e) {
3649
3662
  return e.buildEs5 = !1, e.devMode = !0, e.minifyCss = !1, e.minifyJs = !1, e.hashFileNames = !1,
3650
- e.validateTypes = !1, e._isTesting = !0, e.buildDist = !0, e.flags = e.flags || {},
3651
- e.flags.serve = !1, e.flags.open = !1, e.outputTargets.forEach((e => {
3663
+ e.validateTypes = !1, e._isTesting = !0, e.buildDist = !0, e.flags.serve = !1, e.flags.open = !1,
3664
+ e.outputTargets.forEach((e => {
3652
3665
  "www" === e.type && (e.serviceWorker = null);
3653
3666
  })), e.flags.args.includes("--watchAll") && (e.watch = !0), e;
3654
3667
  }(e);
@@ -3786,9 +3799,14 @@ exports.createJestPuppeteerEnvironment = function createJestPuppeteerEnvironment
3786
3799
  return createTestingSystem();
3787
3800
  }, exports.mockConfig = mockConfig, exports.mockDocument = function mockDocument(e = null) {
3788
3801
  return new index_cjs.MockWindow(e).document;
3789
- }, exports.mockFetch = mockFetch, exports.mockLogger = function mockLogger() {
3790
- return new TestingLogger;
3791
- }, exports.mockModule = (e = {}) => ({
3802
+ }, exports.mockFetch = mockFetch, exports.mockLoadConfigInit = e => ({
3803
+ config: {},
3804
+ configPath: void 0,
3805
+ initTsConfig: !0,
3806
+ logger: void 0,
3807
+ sys: void 0,
3808
+ ...e
3809
+ }), exports.mockLogger = mockLogger, exports.mockModule = (e = {}) => ({
3792
3810
  cmps: [],
3793
3811
  coreRuntimeApis: [],
3794
3812
  collectionName: "",
@@ -3822,7 +3840,18 @@ exports.createJestPuppeteerEnvironment = function createJestPuppeteerEnvironment
3822
3840
  hasVdomText: !1,
3823
3841
  hasVdomXlink: !1,
3824
3842
  ...e
3825
- }), exports.mockWindow = function mockWindow(e = null) {
3843
+ }), exports.mockValidatedConfig = function mockValidatedConfig(e = {}) {
3844
+ var t;
3845
+ const r = mockConfig(e);
3846
+ return {
3847
+ ...r,
3848
+ flags: createConfigFlags(),
3849
+ logger: mockLogger(),
3850
+ outputTargets: null !== (t = r.outputTargets) && void 0 !== t ? t : [],
3851
+ sys: createTestingSystem(),
3852
+ ...e
3853
+ };
3854
+ }, exports.mockWindow = function mockWindow(e = null) {
3826
3855
  return new index_cjs.MockWindow(e);
3827
3856
  }, exports.newE2EPage = async function newE2EPage(e = {}) {
3828
3857
  if (!global.__NEW_TEST_PAGE__) throw new Error("newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.");
@@ -3925,26 +3954,28 @@ exports.createJestPuppeteerEnvironment = function createJestPuppeteerEnvironment
3925
3954
  };
3926
3955
  const o = !0 === e.failOnConsoleError, i = !0 === e.failOnNetworkError;
3927
3956
  t.on("console", (e => {
3928
- "error" === e.type() && (r.push({
3957
+ if ("error" === e.type() && (r.push({
3929
3958
  type: "error",
3930
3959
  message: e.text(),
3931
3960
  location: e.location().url
3932
- }), o && fail(new Error(serializeConsoleMessage(e)))), function t(e) {
3961
+ }), o)) throw new Error(serializeConsoleMessage(e));
3962
+ !function t(e) {
3933
3963
  const t = serializeConsoleMessage(e), r = e.type(), s = "warning" === r ? "warn" : r;
3934
3964
  "debug" !== s && ("function" == typeof console[s] ? console[s](t) : console.log(r, t));
3935
3965
  }(e);
3936
3966
  })), t.on("pageerror", (e => {
3937
- r.push({
3967
+ throw r.push({
3938
3968
  type: "pageerror",
3939
3969
  message: e.message,
3940
3970
  location: e.stack
3941
- }), fail(e);
3971
+ }), e;
3942
3972
  })), t.on("requestfailed", (e => {
3943
- r.push({
3973
+ if (r.push({
3944
3974
  type: "requestfailed",
3945
3975
  message: e.failure().errorText,
3946
3976
  location: e.url()
3947
- }), i ? fail(new Error(e.failure().errorText)) : console.error("requestfailed", e.url());
3977
+ }), i) throw new Error(e.failure().errorText);
3978
+ console.error("requestfailed", e.url());
3948
3979
  })), "string" == typeof e.html ? await e2eSetContent(t, e.html, {
3949
3980
  waitUntil: e.waitUntil
3950
3981
  }) : "string" == typeof e.url ? await e2eGoTo(t, e.url, {
@@ -5,7 +5,7 @@ import type { Config } from '@jest/types';
5
5
  * @param config the Stencil config to use while generating Jest CLI arguments
6
6
  * @returns the arguments to pass to the Jest CLI, wrapped in an object
7
7
  */
8
- export declare function buildJestArgv(config: d.Config): Config.Argv;
8
+ export declare function buildJestArgv(config: d.ValidatedConfig): Config.Argv;
9
9
  /**
10
10
  * Generate a Jest run configuration to be used as a part of the `argv` passed to the Jest CLI when it is invoked
11
11
  * programmatically
@@ -1,9 +1,10 @@
1
1
  import type * as d from '@stencil/core/internal';
2
- export declare function runJest(config: d.Config, env: d.E2EProcessEnv): Promise<boolean>;
2
+ import type { ConfigFlags } from '../../cli/config-flags';
3
+ export declare function runJest(config: d.ValidatedConfig, env: d.E2EProcessEnv): Promise<boolean>;
3
4
  /**
4
5
  * Creates a Stencil test runner
5
6
  * @returns the test runner
6
7
  */
7
8
  export declare function createTestRunner(): any;
8
9
  export declare function includeTestFile(testPath: string, env: d.E2EProcessEnv): boolean;
9
- export declare function getEmulateConfigs(testing: d.TestingConfig, flags: d.ConfigFlags): d.EmulateConfig[];
10
+ export declare function getEmulateConfigs(testing: d.TestingConfig, flags: ConfigFlags): d.EmulateConfig[];
@@ -1,2 +1,2 @@
1
1
  import type * as d from '@stencil/core/internal';
2
- export declare function runJestScreenshot(config: d.Config, env: d.E2EProcessEnv): Promise<boolean>;
2
+ export declare function runJestScreenshot(config: d.ValidatedConfig, env: d.E2EProcessEnv): Promise<boolean>;
@@ -1,7 +1,33 @@
1
- import type { BuildCtx, Cache, CompilerCtx, CompilerSystem, Config, Module } from '@stencil/core/internal';
1
+ import type { BuildCtx, Cache, CompilerCtx, Config, LoadConfigInit, ValidatedConfig, Module, UnvalidatedConfig } from '@stencil/core/internal';
2
2
  import { TestingSystem } from './testing-sys';
3
3
  import { TestingLogger } from './testing-logger';
4
- export declare function mockConfig(sys?: CompilerSystem): Config;
4
+ /**
5
+ * Creates a mock instance of an internal, validated Stencil configuration object
6
+ * the caller
7
+ * @param overrides a partial implementation of `ValidatedConfig`. Any provided fields will override the defaults
8
+ * provided by this function.
9
+ * @returns the mock Stencil configuration
10
+ */
11
+ export declare function mockValidatedConfig(overrides?: Partial<ValidatedConfig>): ValidatedConfig;
12
+ /**
13
+ * Creates a mock instance of a Stencil configuration entity. The mocked configuration has no guarantees around the
14
+ * types/validity of its data.
15
+ * @param overrides a partial implementation of `UnvalidatedConfig`. Any provided fields will override the defaults
16
+ * provided by this function.
17
+ * @returns the mock Stencil configuration
18
+ */
19
+ export declare function mockConfig(overrides?: Partial<UnvalidatedConfig>): UnvalidatedConfig;
20
+ /**
21
+ * Creates a configuration object used to bootstrap a Stencil task invocation
22
+ *
23
+ * Several fields are intentionally undefined for this entity. While it would be trivial to stub them out, this mock
24
+ * generation function operates under the assumption that entities like loggers and compiler system abstractions will
25
+ * be shared by multiple entities in a test suite, who should provide those entities to this function
26
+ *
27
+ * @param overrides the properties on the default entity to manually override
28
+ * @returns the default configuration initialization object, with any overrides applied
29
+ */
30
+ export declare const mockLoadConfigInit: (overrides?: Partial<LoadConfigInit>) => LoadConfigInit;
5
31
  export declare function mockCompilerCtx(config?: Config): CompilerCtx;
6
32
  export declare function mockBuildCtx(config?: Config, compilerCtx?: CompilerCtx): BuildCtx;
7
33
  export declare function mockCache(config?: Config, compilerCtx?: CompilerCtx): Cache;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/testing",
3
- "version": "2.17.0",
3
+ "version": "2.17.2",
4
4
  "description": "Stencil testing suite.",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -1,6 +1,6 @@
1
- import type { Config } from '@stencil/core/internal';
1
+ import type { ValidatedConfig } from '@stencil/core/internal';
2
2
  import type * as puppeteer from 'puppeteer';
3
- export declare function startPuppeteerBrowser(config: Config): Promise<puppeteer.Browser>;
3
+ export declare function startPuppeteerBrowser(config: ValidatedConfig): Promise<puppeteer.Browser>;
4
4
  export declare function connectBrowser(): Promise<any>;
5
5
  export declare function disconnectBrowser(browser: puppeteer.Browser): Promise<void>;
6
6
  export declare function newBrowserPage(browser: puppeteer.Browser): Promise<puppeteer.Page>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,78 @@
1
+ /// <reference types="jest" />
1
2
  import type * as d from '@stencil/core/internal';
2
3
  export declare function shuffleArray(array: any[]): any[];
3
- export declare function expectFiles(fs: d.InMemoryFileSystem, filePaths: string[]): void;
4
- export declare function doNotExpectFiles(fs: d.InMemoryFileSystem, filePaths: string[]): void;
4
+ /**
5
+ * Testing utility to validate the existence of some provided file paths using a specific file system
6
+ *
7
+ * @param fs the file system to use to validate the existence of some files
8
+ * @param filePaths the paths to validate
9
+ * @throws when one or more of the provided file paths cannot be found
10
+ */
11
+ export declare function expectFilesExist(fs: d.InMemoryFileSystem, filePaths: string[]): void;
12
+ /**
13
+ * Testing utility to validate the non-existence of some provided file paths using a specific file system
14
+ *
15
+ * @param fs the file system to use to validate the non-existence of some files
16
+ * @param filePaths the paths to validate
17
+ * @throws when one or more of the provided file paths is found
18
+ */
19
+ export declare function expectFilesDoNotExist(fs: d.InMemoryFileSystem, filePaths: string[]): void;
5
20
  export declare function getAppScriptUrl(config: d.Config, browserUrl: string): string;
6
21
  export declare function getAppStyleUrl(config: d.Config, browserUrl: string): string;
22
+ /**
23
+ * Utility for silencing `console` functions in tests.
24
+ *
25
+ * When this function is first called it grabs a reference to the `log`,
26
+ * `error`, and `warn` functions on `console` and then returns a per-test setup
27
+ * function which sets up a fresh set of mocks (via `jest.fn()`) and then
28
+ * assigns them to each of these functions. This setup function will return a
29
+ * reference to each of the three mock functions so tests can make assertions
30
+ * about their calls and so on.
31
+ *
32
+ * Because references to the original `.log`, `.error`, and `.warn` functions
33
+ * exist in closure within the function, it can use an `afterAll` call to clean
34
+ * up after itself and ensure that the original implementations are restored
35
+ * after the test suite finishes.
36
+ *
37
+ * An example of using this to silence log statements in a single test could look
38
+ * like this:
39
+ *
40
+ * ```ts
41
+ * describe("my-test-suite", () => {
42
+ * const setupConsoleMocks = setupConsoleMocker()
43
+ *
44
+ * it("should log a message", () => {
45
+ * const { logMock } = setupConsoleMocks();
46
+ * myFunctionWhichLogs(foo, bar);
47
+ * expect(logMock).toBeCalledWith('my log message');
48
+ * })
49
+ * })
50
+ * ```
51
+ *
52
+ * @returns a per-test mock setup function
53
+ */
54
+ export declare function setupConsoleMocker(): ConsoleMocker;
55
+ interface ConsoleMocker {
56
+ (): {
57
+ logMock: jest.Mock<typeof console.log>;
58
+ warnMock: jest.Mock<typeof console.warn>;
59
+ errorMock: jest.Mock<typeof console.error>;
60
+ };
61
+ }
62
+ /**
63
+ * the callback that `withSilentWarn` expects to receive. Basically receives a mock
64
+ * as its argument and returns a `Promise`, the value of which is returns by `withSilentWarn`
65
+ * as well.
66
+ */
67
+ declare type SilentWarnFunc<T> = (mock: jest.Mock<typeof console.warn>) => Promise<T>;
68
+ /**
69
+ * Wrap a single callback with a silent `console.warn`. The callback passed in
70
+ * receives the mocking function as an argument, so you can easily make assertions
71
+ * that it is called if necessary.
72
+ *
73
+ * @param cb a callback which `withSilentWarn` will call after replacing `console.warn`
74
+ * with a mock.
75
+ * @returns a Promise wrapping the return value of the callback
76
+ */
77
+ export declare function withSilentWarn<T>(cb: SilentWarnFunc<T>): Promise<T>;
78
+ export {};
@@ -1,2 +1,2 @@
1
- import type { Config, Testing } from '@stencil/core/internal';
2
- export declare const createTesting: (config: Config) => Promise<Testing>;
1
+ import type { ValidatedConfig, Testing } from '@stencil/core/internal';
2
+ export declare const createTesting: (config: ValidatedConfig) => Promise<Testing>;