Coder Social home page Coder Social logo

Comments (10)

jbschrades avatar jbschrades commented on May 26, 2024 2

@hackingbeauty thanks for quick responses - this was pretty new to me.

For anyone coming upon this in the future, here is what I did to fix this.

Per this StackOverflow question - https://stackoverflow.com/questions/47978758/how-to-exclude-node-modules-from-create-react-app-testing - I tried using shallow instead of mount. Didn't work.

So I pulled just AudioContext out of this file - https://github.com/benmurden/Web-Audio-API-Mock/blob/master/AudioContext.mock.js - and added it to __mocks__/react-mic.js per this doc - https://jestjs.io/docs/en/manual-mocks#mocking-node-modules

Tests now pass.

from react-mic.

jbschrades avatar jbschrades commented on May 26, 2024 2
(function() {
  'use strict';

  var AudioContext,
    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) { child[key] = parent[key]; } } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    hasProp = {}.hasOwnProperty;

  AudioContext = (function() {
    function AudioContext() {
      this.destination = new AudioDestinationNode();
      this.listener = new AudioListener();
    }

    AudioContext.prototype.activeSourceCount = 0;

    AudioContext.prototype.sampleRate = 44100;

    AudioContext.prototype.currentTime = 0;

    AudioContext.prototype.createBuffer = function(channels, length, rate) {
      return new AudioBuffer(channels, length, rate);
    };

    AudioContext.prototype.decodeAudioData = function() {};

    AudioContext.prototype.createBufferSource = function() {
      return new AudioBufferSourceNode();
    };

    AudioContext.prototype.createMediaElementSource = function(mediaElement) {
      return new MediaElementAudioSourceNode(mediaElement);
    };

    AudioContext.prototype.createMediaStreamSource = function() {
      return new MediaStreamAudioSourceNode();
    };

    AudioContext.prototype.createOscillator = function() {
      return new OscillatorNode();
    };

    AudioContext.prototype.createScriptProcessor = function(bufferSize) {
      return new ScriptProcessorNode(bufferSize);
    };

    AudioContext.prototype.createAnalyser = function() {
      return new AnalyserNode();
    };

    AudioContext.prototype.createGain = function() {
      return new GainNode();
    };

    AudioContext.prototype.createDelay = function() {
      return new DelayNode();
    };

    AudioContext.prototype.createBiquadFilter = function() {
      return new BiquadFilterNode();
    };

    AudioContext.prototype.createWaveShaper = function() {
      return new WaveShaperNode();
    };

    AudioContext.prototype.createPanner = function() {
      return new PannerNode();
    };

    AudioContext.prototype.createConvolver = function() {
      return new ConvolverNode();
    };

    AudioContext.prototype.createChannelSplitter = function() {
      return new ChannelSplitterNode();
    };

    AudioContext.prototype.createChannelMerger = function() {
      return new ChannelMergerNode();
    };

    AudioContext.prototype.createDynamicsCompressor = function() {
      return new DynamicsCompressorNode();
    };

    AudioContext.prototype.createWaveTable = function() {
      throw new Error("createWaveTable is obsolete. Use createPeriodicWave instead.");
    };

    AudioContext.prototype.createPeriodicWave = function() {
      return new PeriodicWave();
    };

    AudioContext.prototype.createJavaScriptNode = function(bufferSize) {
      return new JavaScriptNode(bufferSize);
    };

    AudioContext.prototype.createGainNode = function() {
      return this.createGain();
    };

    AudioContext.prototype.createDelayNode = function() {
      return this.createDelay();
    };

    return AudioContext;

  })();

  window.AudioContext = AudioContext;

})();

from react-mic.

jahirfiquitiva avatar jahirfiquitiva commented on May 26, 2024 1

Hey @jbschrades where did you exactly put this file? I can't get it to work in my CRA app 😕

from react-mic.

hackingbeauty avatar hackingbeauty commented on May 26, 2024

OK, can you fix it and issue a PR? What is your test suite?

from react-mic.

jbschrades avatar jbschrades commented on May 26, 2024

Using jest with create-react-app. I can't get it to work and what is there looks correct. Maybe the problem is with jest?

from react-mic.

hackingbeauty avatar hackingbeauty commented on May 26, 2024

from react-mic.

jbschrades avatar jbschrades commented on May 26, 2024

It's just a basic integration test to check if the app renders. Failing on the import statement in a component down in the tree.

import { ReactMic } from "react-mic"

I'm not testing it directly.

from react-mic.

hackingbeauty avatar hackingbeauty commented on May 26, 2024

from react-mic.

Ashersam avatar Ashersam commented on May 26, 2024

mocks/react-mic.js

I got stuck with same issue. Can you expose this react-mic.js file? I didn't quite get how you pulled AudioContext out of this file - https://github.com/benmurden/Web-Audio-API-Mock/blob/master/AudioContext.mock.js

from react-mic.

bshahrok avatar bshahrok commented on May 26, 2024
(function() {
  'use strict';

  var AudioContext,
    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) { child[key] = parent[key]; } } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    hasProp = {}.hasOwnProperty;

  AudioContext = (function() {
    function AudioContext() {
      this.destination = new AudioDestinationNode();
      this.listener = new AudioListener();
    }

    AudioContext.prototype.activeSourceCount = 0;

    AudioContext.prototype.sampleRate = 44100;

    AudioContext.prototype.currentTime = 0;

    AudioContext.prototype.createBuffer = function(channels, length, rate) {
      return new AudioBuffer(channels, length, rate);
    };

    AudioContext.prototype.decodeAudioData = function() {};

    AudioContext.prototype.createBufferSource = function() {
      return new AudioBufferSourceNode();
    };

    AudioContext.prototype.createMediaElementSource = function(mediaElement) {
      return new MediaElementAudioSourceNode(mediaElement);
    };

    AudioContext.prototype.createMediaStreamSource = function() {
      return new MediaStreamAudioSourceNode();
    };

    AudioContext.prototype.createOscillator = function() {
      return new OscillatorNode();
    };

    AudioContext.prototype.createScriptProcessor = function(bufferSize) {
      return new ScriptProcessorNode(bufferSize);
    };

    AudioContext.prototype.createAnalyser = function() {
      return new AnalyserNode();
    };

    AudioContext.prototype.createGain = function() {
      return new GainNode();
    };

    AudioContext.prototype.createDelay = function() {
      return new DelayNode();
    };

    AudioContext.prototype.createBiquadFilter = function() {
      return new BiquadFilterNode();
    };

    AudioContext.prototype.createWaveShaper = function() {
      return new WaveShaperNode();
    };

    AudioContext.prototype.createPanner = function() {
      return new PannerNode();
    };

    AudioContext.prototype.createConvolver = function() {
      return new ConvolverNode();
    };

    AudioContext.prototype.createChannelSplitter = function() {
      return new ChannelSplitterNode();
    };

    AudioContext.prototype.createChannelMerger = function() {
      return new ChannelMergerNode();
    };

    AudioContext.prototype.createDynamicsCompressor = function() {
      return new DynamicsCompressorNode();
    };

    AudioContext.prototype.createWaveTable = function() {
      throw new Error("createWaveTable is obsolete. Use createPeriodicWave instead.");
    };

    AudioContext.prototype.createPeriodicWave = function() {
      return new PeriodicWave();
    };

    AudioContext.prototype.createJavaScriptNode = function(bufferSize) {
      return new JavaScriptNode(bufferSize);
    };

    AudioContext.prototype.createGainNode = function() {
      return this.createGain();
    };

    AudioContext.prototype.createDelayNode = function() {
      return this.createDelay();
    };

    return AudioContext;

  })();

  window.AudioContext = AudioContext;

})();

That did not work for me, I am still getting the same error. What is your Node and npm version?

from react-mic.

Related Issues (20)

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.