Skip to content

Coverage not collected in Embroider >3.1 #386

Closed

Description

@chrismllr

Versions:

"ember-cli": "~4.12.1",
"@embroider/compat": "^3.2.1",
"@embroider/core": "^3.2.1",
"@embroider/webpack": "^3.1.5",
"ember-cli-code-coverage": "2.0.0"

Utilizing embroider >2 (as of writing, 3.2) coverage is not generated.

From initial debugging, a couple things ive noticed:

  • The stableWorkspaceDir (@embroider/compat) method returns a directory that does not match the build directory that is printed when the build completes before tests are run (Built in ....) -- Unsure if this is actually an issue, or Istanbul simply needs an empty directory to work from
  • testMiddleware method is registered, but the app never POSTs back (coverageHandler is never invoked)
  • If running with --server flag, sendCoverage is invoked, but window.__coverage__ is empty

Repro: https://github.com/chrismllr/repro-code-coverage-embroider

Activity

  1. changed the title [-]Coverage not collected Embroider >2[/-] [+]Coverage not collected in Embroider >2[/+] on Aug 8, 2023
  2. chrismllr commented on Aug 8, 2023

    @chrismllr
    ContributorAuthor

    Attempted to point to this version of the repo with no luck:
    #382 (comment)

  3. chrismllr commented on Aug 8, 2023

    @chrismllr
    ContributorAuthor

    Still digging, but It looks like the this package uses stableWorkspaceDir to pass istanbul the correct directory (the one embroider will build into):

    if (opts.embroider === true) {
      let {
        stableWorkspaceDir,
      } = require('@embroider/compat/src/default-pipeline');
      cwd = stableWorkspaceDir(cwd, process.env.EMBER_ENV);
    }

    But in later versions of embroider, i'm unsure what is used to determine that build dir:

    embroider/compat v1.8.3 (older version)

    function defaultPipeline(emberApp, packager, options = {}) {
        let outputPath;
        let addons;
        if (process.env.REUSE_WORKSPACE) {
            addons = new _1.PrebuiltAddons(emberApp, options, process.env.REUSE_WORKSPACE);
        }
        else {
            if (process.env.SAVE_WORKSPACE) {
                options.workspaceDir = process.env.SAVE_WORKSPACE;
            }
            else {
                options.workspaceDir = stableWorkspaceDir(emberApp.project.root); // <----------- Same method used here
            }
            emberApp.project.ui.write(`Building into ${options.workspaceDir}\n`);
            addons = new _1.Addons(emberApp, options);
            addons.ready().then(result => {
                outputPath = result.outputPath;
            });
        }
        if (process.env.STAGE1_ONLY) {
            return (0, broccoli_merge_trees_1.default)([addons.tree, (0, broccoli_file_creator_1.default)('.stage1-output', () => outputPath)]);
        }
        let embroiderApp = new _1.App(emberApp, addons, options);
        if (process.env.STAGE2_ONLY || !packager) {
            return (0, broccoli_merge_trees_1.default)([embroiderApp.tree, (0, broccoli_file_creator_1.default)('.stage2-output', () => outputPath)]);
        }
        let BroccoliPackager = (0, core_1.toBroccoliPlugin)(packager);
        let variants = (options && options.variants) || defaultVariants(emberApp);
        return new BroccoliPackager(embroiderApp, variants, options && options.packagerOptions);
    }

    embroider/compat v3.2.1 (recent version)

    // Method not used; unsure how build dir set
    
    function defaultPipeline(emberApp, packager, options = {}) {
        let outputPath;
        let addons;
        let embroiderApp = new _1.App(emberApp, options);
        addons = new _1.Addons(embroiderApp);
        addons.ready().then(result => {
            outputPath = result.outputPath;
        });
        if (process.env.STAGE1_ONLY) {
            return (0, broccoli_merge_trees_1.default)([addons.tree, (0, broccoli_file_creator_1.default)('.stage1-output', () => outputPath)]);
        }
        if (process.env.STAGE2_ONLY || !packager) {
            return (0, broccoli_merge_trees_1.default)([embroiderApp.asStage(addons).tree, (0, broccoli_file_creator_1.default)('.stage2-output', () => outputPath)]);
        }
        let BroccoliPackager = (0, core_1.toBroccoliPlugin)(packager);
        let variants = (options && options.variants) || defaultVariants(emberApp);
        return new BroccoliPackager(embroiderApp.asStage(addons), variants, options && options.packagerOptions);
    }
  4. chrismllr commented on Aug 9, 2023

    @chrismllr
    ContributorAuthor

    Looks like a new API was introduced to locate the embroider dir via this commit, locateEmbroiderWorkingDir, which when using, seems to do the trick for me.

    embroider-build/embroider@9e078f0

    This is a very recent addition, so there would likely need to use something like ember-cli-version-checker to decide on the method of resolving that embroider dir. @kategengler (or other maintainers) I may just be missing something entirely, but if you feel like that's a logical plan of action I can put up a PR for it

  5. kategengler commented on Aug 9, 2023

    @kategengler
    Collaborator

    cc @mansona since I believe at one point was going to look at compatibility and may know the answer

  6. changed the title [-]Coverage not collected in Embroider >2[/-] [+]Coverage not collected in Embroider >3.15[/+] on Aug 9, 2023
  7. changed the title [-]Coverage not collected in Embroider >3.15[/-] [+]Coverage not collected in Embroider >3.1[/+] on Aug 9, 2023
  8. chrismllr commented on Aug 9, 2023

    @chrismllr
    ContributorAuthor

    Took a stab at it, to give an example of what's working for me 👉 #387

  9. chrismllr commented on Jan 4, 2024

    @chrismllr
    ContributorAuthor

    Closed via 2.0.3 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions