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

Coverage not collected in Embroider >3.1 #386

Closed
chrismllr opened this issue Aug 8, 2023 · 6 comments
Closed

Coverage not collected in Embroider >3.1 #386

chrismllr opened this issue Aug 8, 2023 · 6 comments

Comments

@chrismllr
Copy link
Contributor

chrismllr commented Aug 8, 2023

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

@chrismllr chrismllr changed the title Coverage not collected Embroider >2 Coverage not collected in Embroider >2 Aug 8, 2023
@chrismllr
Copy link
Contributor Author

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

@chrismllr
Copy link
Contributor Author

chrismllr commented Aug 8, 2023

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);
}

@chrismllr
Copy link
Contributor Author

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

@kategengler
Copy link
Collaborator

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

@chrismllr chrismllr changed the title Coverage not collected in Embroider >2 Coverage not collected in Embroider >3.15 Aug 9, 2023
@chrismllr chrismllr changed the title Coverage not collected in Embroider >3.15 Coverage not collected in Embroider >3.1 Aug 9, 2023
@chrismllr
Copy link
Contributor Author

chrismllr commented Aug 9, 2023

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

@chrismllr
Copy link
Contributor Author

Closed via 2.0.3 🎉

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

No branches or pull requests

2 participants