Code Monkey home page Code Monkey logo

Comments (10)

squidfunk avatar squidfunk commented on May 3, 2024 1

make sure to call the respective functions from the setup hooks of your test framework or from within your tests (e.g. beforeEach, describe etc.)

I thought about this too, but testing frameworks have different names for functions. For mocha and jasmine it's it, for others it's test, which is why I tried to describe it without getting into too much detail. However, if more people stumble over this, we can adjust it

from karma-viewport.

dakur avatar dakur commented on May 3, 2024

Here is full karma.config.js:

const webpackConfig = require('./webpack.config');

process.env.CHROMIUM_BIN = require('puppeteer').executablePath();
module.exports = (config) => {
	config.set({
		basePath: '',
		files: [
			{
				pattern: 'src/**/*.spec.ts',
				watched: false,
			},
		],

		frameworks: ['mocha', 'viewport'],
		client: {
			mocha: {
				timeout: 30000,
			},
		},

		browserNoActivityTimeout: 60000,

		mime: {
			'text/x-typescript': ['ts', 'tsx'],
		},

		preprocessors: {
			'src/**/*.spec.ts': ['webpack'],
		},
		webpack: {
			mode: 'development',
			devtool: 'inline-source-map',
			resolve: {
				extensions: ['.ts', '.tsx', '.js', '.json'],
			},
			module: webpackConfig.module,
		},

		reporters: ['dots'],

		port: 9876,
		colors: true,
		logLevel: config.LOG_INFO,
		autoWatch: true,
		singleRun: false,

		browsers: ['ChromiumHeadless'],
		concurrency: Infinity,
	});
};

from karma-viewport.

squidfunk avatar squidfunk commented on May 3, 2024

I just tested karma-viewport in a mint project and it works just fine. It's likely related to your project configuration, but really hard to debug this remotely. I don't see any immediate problems from the configuration you posted, as it's basically the same as the integration test. However, the devil is in the details. My advice would be to check whether other plugins that add variables to the global scope work as expected. If not, it could be this project, otherwise it's something more general.

from karma-viewport.

dakur avatar dakur commented on May 3, 2024

Thank you for your reply! Looks like you don't use puppeteer, so it may be problem in there. I'll try to figure it out.

from karma-viewport.

dakur avatar dakur commented on May 3, 2024

Hm, it does not seem to be the problem. I've created completely new testing project and ran:

yarn init && yarn add --dev karma karma-chrome-launcher karma-viewport

In my package.json I have (basically just added scripts):

{
	"name": "test-test",
	"version": "0.0.1",
	"main": "index.js",
	"license": "MIT",
	"devDependencies": {
		"karma": "^5.2.2",
		"karma-chrome-launcher": "^3.1.0",
		"karma-viewport": "^1.0.7"
	},
	"scripts": {
		"test": "karma start karma.conf.js"
	}
}

I've created test.spec.js:

viewport.set(1000, 50);

And reduced karma.config.js to:

module.exports = (config) => {
	config.set({
		files: [
			'test.spec.js',
		],
		frameworks: ['viewport'],
		browsers: ['Chrome'],
	});
};

Then, when I run yarn run test, I still end up with given message:
image

I was not sure if it is not just my Git Bash problem so I ran it on cmd.exe as well as PowerShell, but the result is still the same.

from karma-viewport.

squidfunk avatar squidfunk commented on May 3, 2024

Okay, that's weird. Unfortunately, I don't have the time to debug this with you together, but I think the best idea would be to check out some projects that use this library successfully and see how they've done it. Might I suggest:

from karma-viewport.

dakur avatar dakur commented on May 3, 2024

Thank you, suggestions helped. I've fiddled with https://github.com/niksy/advertol-context-media-query and the problem appeared: you can not use viewport too early – which basically means outside of a function. So this will make an error:

viewport.set(x, y);

describe('...', () => {
  it('...', () => {});
});

but this works:

beforeEach(() => {
  viewport.set(x, y);
});

// and/or

describe('...', () => {
  it('...', () => {
    viewport.set(x, y);
  });
});

It kind of makes sense (it's like working with DOM before DOMContentLoaded), but it's very confusing for us newcomers who do not know how internals of this testing ecosystem work. It would be worthy to mention it in the docs definitely. :-)

from karma-viewport.

squidfunk avatar squidfunk commented on May 3, 2024

Ah great you found the issue. I was assuming that you'd use it inside of a function, but yes, this makes sense. It's also great we've documented it here for future users.

I guess this issue can be closed then?

from karma-viewport.

squidfunk avatar squidfunk commented on May 3, 2024

I added a note in 4846275.

from karma-viewport.

dakur avatar dakur commented on May 3, 2024

makes sure to call the respective functions from the setup hooks of your test framework or from within your tests

Not pretty sure I would understand this test slang, but maybe it's just me test newbie. :-) Some examples would help me understand:

make sure to call the respective functions from the setup hooks of your test framework or from within your tests (e.g. beforeEach, describe etc.)

Yes, this issue can be closed. Thank you.

from karma-viewport.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.