Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Next Version #507

Merged
merged 1 commit into from
Aug 31, 2022
Merged

Publish Next Version #507

merged 1 commit into from
Aug 31, 2022

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jun 14, 2022

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

Releases

pleasantest@3.0.0

Major Changes

  • #561 b565e0b Thanks @calebeby! - Normalize whitespace in element accessible names in getAccessibilityTree. Markup with elements which have an accessible name that includes irregular whitespace, like non-breaking spaces, will now have a different output for getAccessibilityTree snapshots. Previously, the whitespace was included, now, whitespace is replaced with a single space.

  • #535 dc6f81c Thanks @calebeby! - Values exported from runJS are now available in Node.

    For example:

    test(
      'receiving exported values from runJS',
      withBrowser(async ({ utils }) => {
        // Each export is available in the returned object.
        // Each export is wrapped in a JSHandle, meaning that it points to an in-browser object
        const { focusTarget, favoriteNumber } = await utils.runJS(`
          export const focusTarget = document.activeElement
          export const favoriteNumber = 20
        `);
    
        // Serializable JSHandles can be unwrapped using JSONValue:
        console.log(await favoriteNumber.jsonValue()); // Logs "20"
    
        // A JSHandle<Element>, or ElementHandle is not serializable
        // But we can pass it back into the browser to use it (it will be unwrapped in the browser):
    
        await utils.runJS(
          `
          // The import.meta.pleasantestArgs context object receives the parameters passed in below
          const [focusTarget] = import.meta.pleasantestArgs;
          console.log(focusTarget) // Logs the element in the browser
          `,
          // Passing the JSHandle in here passes it into the browser (unwrapped) in import.meta.pleasantestArgs
          [focusTarget],
        );
      }),
    );

    We've also introduced a utility function to make it easier to call JSHandles that point to functions, makeCallableJSHandle. This function takes a JSHandle<Function> and returns a node function that calls the corresponding browser function, passing along the parameters, and returning the return value wrapped in Promise<JSHandle<T>>:

    // new import:
    import { makeCallableJSHandle } from 'pleasantest';
    
    test(
      'calling functions with makeCallableJSHandle',
      withBrowser(async ({ utils }) => {
        const { displayFavoriteNumber } = await utils.runJS(`
          export const displayFavoriteNumber = (number) => {
            document.querySelector('.output').innerHTML = "Favorite number is: " + number
          }
        `);
    
        // displayFavoriteNumber is a JSHandle<Function>
        // (a pointer to a function in the browser)
        // so we cannot call it directly, so we wrap it in a node function first:
    
        const displayFavoriteNumberNode = makeCallableJSHandle(
          displayFavoriteNumber,
        );
    
        // Note the added `await`.
        // Even though the original function was not async, the wrapped function is.
        // This is needed because the wrapped function needs to asynchronously communicate with the browser.
        await displayFavoriteNumberNode(42);
      }),
    );

    For TypeScript users, runJS now accepts a new optional type parameter, to specify the exported types of the in-browser module that is passed in. The default value for this parameter is Record<string, unknown> (an object with string properties and unknown values). Note that this type does not include JSHandles, those are wrapped in the return type from runJS automatically.

    Using the first example, the optional type would be:

    test(
      'receiving exported values from runJS',
      withBrowser(async ({ utils }) => {
        const { focusTarget, favoriteNumber } = await utils.runJS<{
          focusTarget: Element;
          favoriteNumber: number;
        }>(`
          export const focusTarget = document.activeElement
          export const favoriteNumber = 20
        `);
      }),
    );

    Now focusTarget automatically has the type JSHandle<Element> and favoriteNumber automatically has the type JSHandle<number>. Without passing in the type parameter to runJS, their types would both be JSHandle<unknown>.

  • #541 39085ac Thanks @calebeby! - injectHTML now executes script tags in the injected markup by default. This can be disabled by passing the executeScriptTags: false option as the second parameter.

    For example, the script tag is now executed by default:

    await utils.injectHTML(
      "<script>document.querySelector('div').textContent = 'changed'</script>",
    );

    But by passing executeScriptTags: false, we can disable execution:

    await utils.injectHTML(
      "<script>document.querySelector('div').textContent = 'changed'</script>",
      { executeScriptTags: false },
    );
  • #535 dc6f81c Thanks @calebeby! - The way that runJS receives parameters in the browser has changed. Now, parameters are available as import.meta.pleasantestArgs instead of through an automatically-called default export.

    For example, code that used to work like this:

    test(
      'old version of runJS parameters',
      withBrowser(async ({ utils }) => {
        // Pass a variable from node to the browser
        const url = isDev ? 'dev.example.com' : 'prod.example.com';
    
        await utils.runJS(
          `
          // Parameters get passed into the default-export function, which is called automatically
          export default (url) => {
            console.log(url)
          }
          `,
          // array of parameters passed here
          [url],
        );
      }),
    );

    Now should be written like this:

    test(
      'new version of runJS parameters',
      withBrowser(async ({ utils }) => {
        // Pass a variable from node to the browser
        const url = isDev ? 'dev.example.com' : 'prod.example.com';
    
        await utils.runJS(
          `
          // Parameters get passed as an array into this context variable, and we can destructure them
          const [url] = import.meta.pleasantestArgs
          console.log(url)
          // If we added a default exported function here, it would no longer be automatically called.
          `,
          // array of parameters passed here
          [url],
        );
      }),
    );

    This is a breaking change, because the previous mechanism for receiving parameters no longer works, and functions that are default exports from runJS are no longer called automatically.

  • #506 7592994 Thanks @calebeby! - Drop support for Node 12 and 17

Minor Changes

  • #557 7bb10e0 Thanks @calebeby! - Update @testing-library/dom to 8.17.1 and @testing-library/jest-dom to 5.16.5

@github-actions github-actions bot force-pushed the changeset-release/main branch 6 times, most recently from d29ca24 to 3b53c1f Compare June 21, 2022 23:50
@github-actions github-actions bot force-pushed the changeset-release/main branch 5 times, most recently from 203be1e to cb2cf6a Compare July 1, 2022 15:57
@github-actions github-actions bot force-pushed the changeset-release/main branch 4 times, most recently from 979d26f to 6d5f314 Compare July 14, 2022 18:40
@github-actions github-actions bot force-pushed the changeset-release/main branch 5 times, most recently from d1e17a6 to 6152923 Compare July 20, 2022 21:28
@github-actions github-actions bot force-pushed the changeset-release/main branch 10 times, most recently from b130e72 to 0e33683 Compare August 1, 2022 18:45
@github-actions github-actions bot force-pushed the changeset-release/main branch 8 times, most recently from 8447f2c to 4eb67c3 Compare August 8, 2022 16:08
@github-actions github-actions bot force-pushed the changeset-release/main branch 3 times, most recently from b1207b2 to fa4dcaa Compare August 15, 2022 15:33
@github-actions github-actions bot force-pushed the changeset-release/main branch 6 times, most recently from c1953e1 to aa06685 Compare August 23, 2022 22:00
@github-actions github-actions bot force-pushed the changeset-release/main branch 6 times, most recently from 26749f7 to 038c23d Compare August 31, 2022 16:23
@github-actions github-actions bot force-pushed the changeset-release/main branch from 038c23d to 1daf3c6 Compare August 31, 2022 21:00
@calebeby calebeby merged commit 2dc2b79 into main Aug 31, 2022
@calebeby calebeby deleted the changeset-release/main branch August 31, 2022 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant